views:

526

answers:

4

Hi Javascript gurus, I have this Javascript code which is working fine on Firefox , but it is not working on IE 7. Any ideas why?

Here is the code

function TestWindow()
{
     SimpleWindow('Default.aspx', 'Simple Test', 200, 200, 'yes')
}

function SimpleWindow(mypage,myname,w,h,scroll)
{

    var win= null;

    var winl = (screen.width-w)/2;


    var wint = (screen.height-h)/2;

    settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no'

    win=window.open(mypage,myname,settings)

    if(parseInt(navigator.appVersion) >= 4)
        {
            win.window.focus();
        }
    }
+4  A: 

For myname parameter use only a-zA-Z0-9 characters. IE doesn't like any other, especially whitespace characters.

Rafael
Are you sure that is the second parameters refers to the title of the page. So in IE7 it could not have space for the title?
Shiva
@Shiva - that isn't the title of the page (that comes from the html), it's the name of the window.
seth
yes, I'm sure of my answer. The second parameter of window.open is windows' name to which you can then refer in target attributes. It isn't the windows title.
Rafael
Thanks man. It worked once I removed the whitespace characters from the title.
Shiva
A: 

Check popup blockers

SLaks
+3  A: 

You may have realized that IE is giving the error "Invalid argument."

IE doesn't seem to like window names with spaces in them. Change 'Simple Test' to 'SimpleTest' etc.

Ates Goral
Sorry Ates Goral, that did not work.
Shiva
Are you sure? Because I have your code in front of me, working after I changed the name to 'SimpleTest'.
Ates Goral
You are right. that was it!!! Thank you
Shiva
A: 

Check for reserved words. Your parameter name "scroll" is probably messing up your code in IE.

mgs