Filip
Filip

Reputation: 81

Javascript popup - Works in FF & Chrome, fails in IE

I can't seem to figure out why the following simple popup will not work in IE9. FF & Chrome popup as expected, but IE does not appear to do anything when the link is clicked. I tried the IE9 debugger, but didn't get any helpful information out of it.

In the head section:

<script type="text/javascript" language="JavaScript">
    function JSPopup(linkref) {
        window.open(linkref,"Report Definitions","width=600,height=480");
        return false;
    }

In the body:

<a href="#" onClick="JSPopup('./Web Report Definitions.html')"> <strong>Report Definitions</strong> </a> 

Thanks for your help,

Filip

Upvotes: 2

Views: 904

Answers (2)

Filip
Filip

Reputation: 81

Turns out the problem was the name given to the popup - IE doesn't allow spaces, FF & Chrome do:

window.open(linkref,"Report Definitions","width=600,height=480"); 

needed to be changed to:

window.open(linkref,"ReportDefinitions","width=600,height=480"); 

This works across browsers.

Filip

Upvotes: 2

Braunson
Braunson

Reputation: 717

This is part of the security changes made in IE6. Now you can only call "window.open" from within a user-initiated event. For example, your code would work inside an element's onclick event. The "window.open" http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx MSDN page says this:

"This method must use a user-initiated action, such as clicking on a link or tabbing to a link and pressing enter, to open a pop-up window. The Pop-up Blocker feature in Internet Explorer 6 blocks windows that are opened without being initiated by the user."

Example...

function popUpWin(url,wtitle,wprop){
   if (!window.open){ return; } // checking if we can't do this basic function

   // Kill if(win), since win was a local var this was a usless check
   var win = window.open(url,wtitle,wprop);

   // next line important in case you open multiple with the same 'wtitle' 
   // to make sure the window is reused and refocused.
   if (win && win.focus){ win.focus(); }

   return false;
} 

Upvotes: 1

Related Questions