SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    Omaha, NE
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Verify a window is open

    I'm working on a script that needs to check if a window is open.
    The window is opened from a different function then the one that
    has to do the verification. Will this work? What is the best way
    to do this?


    The first code block is done in javascript and needs to
    do the check for the error near the *****

    Code:
    function spellChecker() 
    	{
    	var useRng; 
    	 words = new Array();
    	 wordSugs = new Array();
    	 useRng = getHighlightedRange (false);
    	 if (useRng.text == "") 
    		{
    	 var useRng = document.body.createTextRange( );
    	 useRng.moveToElementText(document.all.oDiv);
    	 }
    	 spellRng = useRng.duplicate();
    	 vbCheckSpell(spellRng.text);
    	 document.documentElement.style.cursor='auto';
    	 if (words.length == 0) 
    		{
     
    // *************************************
    // I need to check to see if the window was opened here, 
    //if not, fire off the alert 
    	 alert('No misspelled words found!');
     
    return;
    	 }
    	 spellIdx = -1;
    	 spellProcessAction("");
    	}

    The second block of code is done in VBScript and opens
    the window if there is an error. (popupWin)

    Code:
    <script language="VBScript">
    	function vbCheckSpell(theVal)
    	Dim objWord
    	Dim objDoc
    	Dim NumberOfWords
    	Dim NumberOfErrors
    	Dim suggs 
    	Dim i
    	Dim j
    On Error Resume Next
    set objWord = CreateObject("word.Application")
    if err.Number <> 0 then
    msgbox("Unable to open MS Word." & vbCrLf & "Please be sure word is installed and your security setting allows scripting!")
    popupWin = window.open("DHTML_editor_ActiveXerror.htm","ErrorWindow","left=0,top=0, width=500, height=650,scrollbars=1")
    </script>

    There is an "else" with the above code, but that is the important part of the vbscript. Also, the above order is how it appears on the page.

    Is this possible?

    Thanks!
    "Oh, you hate your job? Why didn't you say so? There's a support group for that.
    It's called EVERYBODY, and they meet at the bar."

    --Drew Carey

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Is your window named "popWin", like your VBScript says it is? If so, then this code should work:
    Code:
    if (popWin) {
      //your window is available
    } else {
      //your window is unavailable.
    }

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    VBScript not my forte, but as a general rule:

    1) Declare a global variable to hold the new window object
    2) Return the call to window.open() to that variable (returns the window object)
    3) Use that object to program the new window

    So....
    Code:
    var popupWin = null;
    
    function popup_opener()
    {
    ............
    ............
          if (!popupWin || popupWin.closed)
              popupWin = window.open('url', 'popupWin', '...feature string...');
          if (popupWin && !popupWin.closed)
              popupWin.focus();
    }
    The window.closed property - don't confuse this with the window.close() method - is a Boolean flag indicating if the window has been closed, to avoid scripting errors. Not necessary to name the window the same as the global variable but, helps simplify things.
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •