The Google Toolbar and Popup Window Script Error

See the JavaScript and Windows section for all the information you could ever possibly need about doing windows with JavaScript.

The Problem

Recently I've encountered a huge amount of script error notifications (using Internet Explorer's script debugging tool) while surfing. It has to do with popup windows which are opened automatically via a script - you know, the kind of popups we all hate - and the Google Toolbar Popup Blocker (possibly other popup blockers too).

While most non-developers will not have script debugging turned on, and the Google Toolbar itself warns of these errors and offers to turn notification off, sites with high tech audiences or those selling high tech services should take heed and avoid looking ignorant - not to mention annoying visitors who need to have this browser feature enabled (ME!).

The Fix

The fix is extremely simple - the hardest part is remembering when to use it. First, it is only neccessary when your popup script is the kind that launches popups automatically. Second, this kind of script requires the fix only when additional actions (other than launching it) are performed on the popup, such as focusing the popup window in front of its opener. This is because of the logical action sequence of the script and the blocker, even though it happens in a matter of milliseconds;
-the script attempts to launch the window
-the blocker kills the attempted launch (I assume it never actually launches because if it did launch and then was killed, it would not have a null value - and it does. Perhaps it intercepts open method's returned value to the browser via the void keyword?)
-the script attempts to perform another action on the popup
-an error notification if produced because the scripting engine cannot find the object on which it is being instructed to perform the action
-I'm annoyed as I click "No" to the "Do you wish to Debug?" prompt

Sample Script

var pop = open("annoy.htm","advert","width=400,height=300,top=80,left=375")

if(pop != null){// before attempting additional scripting of the popup, make sure it exists!!
pop.focus()
}
That's it! A simple if statement to see if the value of the variable is null prevents error notifications while using IE and the Google Toolbar's popup blocker. Other blockers may work by simply closing the popup. In that case, the value would not be null and an additional evaluation in the same if statement would be required:
var pop = open("annoy.htm","advert","width=400,height=300,top=80,left=375")

if(pop && !pop.closed){// before attempting additional scripting of the popup, make sure it exists and has not been closed!!
pop.focus()
}
See the JavaScript and Windows section for all the information you could ever possibly need about doing windows with JavaScript.


Home | Contact

©2002-2004 Jennifer Madden