Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

I just can't nail this javascript error

Options
  • 29-09-2009 11:26pm
    #1
    Registered Users Posts: 1,795 ✭✭✭


    Hi all,
    this will be very simple for one of you to solve. On the following page:

    http://www.dezynamite.com/promotional.html

    I have a script for a pop-up with a contact form. I can get it to work on all the browsers I have in the office (FF, Safari, Opera, IE8), but where I am at work right now, IE7 won't display it.

    ~~The script is tied to the 'Brochure Request' graphic at bottom-right, 'CLICK HERE' in the text opposite it, and 'Catalogue Request' in the footer.~~

    Feedback appreciated on how I can fix it, thanks in advance,

    Seanie.


Comments

  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Seanie M wrote: »
    Hi all,
    this will be very simple for one of you to solve. On the following page:

    http://www.dezynamite.com/promotional.html

    I have a script for a pop-up with a contact form. I can get it to work on all the browsers I have in the office (FF, Safari, Opera, IE8), but where I am at work right now, IE7 won't display it.

    ~~The script is tied to the 'Brochure Request' graphic at bottom-right, 'CLICK HERE' in the text opposite it, and 'Catalogue Request' in the footer.~~

    Feedback appreciated on how I can fix it, thanks in advance,

    Seanie.

    url being passed to the function is "brochure-request.html", however the window.open function is called with the parameters

    window.open(url,'brochure-request.html',atts);

    Since the second parameter is meant to be a window name, it's going to screw up because of the ".";

    window.open(url,"newWindow",atts);

    should do the trick for you.


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Only had a really brief look at it.. I'm bashing my head against some JS myself here :)

    http://www.w3schools.com/htmldom/met_win_open.asp

    According to the parameter list here it looks like you have some rogue params,
    screenX,screenY, left don't seem to be listed in the attributes. Maybe try removing them. Other browsers are probably just ignoring them.


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Thanks for the quick replies guys, I'll try those tips and see what happens.

    Seanie.


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Liam Byrne wrote: »
    url being passed to the function is "brochure-request.html", however the window.open function is called with the parameters

    window.open(url,'brochure-request.html',atts);

    Since the second parameter is meant to be a window name, it's going to screw up because of the ".";

    window.open(url,"newWindow",atts);

    should do the trick for you.

    I tried this first. It still works on my browsers here, but does anyone else want to try it in their IE7 please?

    :)


  • Registered Users Posts: 6,464 ✭✭✭MOH


    Only have IE6 here in work, but getting a javascript error in that.
    Line: 105
    Char: 4
    Error: Invalid argument
    Code: 0
    URL: http://www.dezynamite.com/promotional.html
    

    Looks like it might still be the issue Liam Byrne pointed out?


  • Advertisement
  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Take the hyphon out of the page name
    Remove show from your atts
    Remove screenX and screenY from atts too

    This works for me in IE (5.5,6,7,8) FF3, Chrome and Opera 9.
    var atts='width='+width+',height='+height+',top='+from_top+',';
    atts+= from_top+',left='+from_left+',toolbar='+toolbar;			
    atts+=',location='+location+',directories='+directories+',status='+status;		
    atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;		
    
    window.open(url,'brochurerequest',atts);
    

    They way you've defined atts just made it hard to decipher what was going on.

    Edit: ScreenX and ScreenY options aren't the main cause, the hyphon is I believe but still if they're not in the spec then no point using them


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Thanks once again folks. I have tried Mad_Max's suggestion as his attempt worked for him. It is still working for me in my browsers here, albeit the height of the popup window is now full height, but I can live with that. How about those of you with IE7 and below?

    Seanie.


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Seanie M wrote: »
    Thanks once again folks. I have tried Mad_Max's suggestion as his attempt worked for him. It is still working for me in my browsers here, albeit the height of the popup window is now full height, but I can live with that. How about those of you with IE7 and below?

    Seanie.

    I'm confused. Is it working for you in IE7 now or no?

    The code I pasted above worked in all versions of IE (I have a emulator for them all) as well as all other major browsers.


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Mad_Max wrote: »
    I'm confused. Is it working for you in IE7 now or no?

    The code I pasted above worked in all versions of IE (I have a emulator for them all) as well as all other major browsers.

    I don't have IE7, that's why I am relying on you guys that have it to tell me! I've got all the others, inc IE8.


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Ah sorry, thought you did.

    Nope - As Liam mentioned you need to remove the dot from the page name now.

    Remove that and it works fine for me on IE7


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 8,870 Mod ✭✭✭✭mewso


    Doesn't work in IE8 for me or in IE8 compatability mode (which is supposed to be equivilent to IE7 by the by). I still see the dot in the second paramater of window.open. I will resist any comment on using window.open in the first place :)


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Seanie M wrote: »
    I tried this first.

    Er - no you haven't. What part of this are you not getting, OP ?

    You have removed the hyphen, but you are still either confusing or trying to name the window object using the html filename - why ? As I said above,
    Liam Byrne wrote: »
    Since the second parameter is meant to be a window name, it's going to screw up because of the ".";

    You STILL have the "." : window.open(url,"brochurerequest.html",atts);

    As pointed out above 3 or 4 times, the second parameter SHOULD NOT be the filename, or any variation of it -

    - the first parameter is the filename, and that's being passed using the variable "url"
    - the second parameter is an arbitrary name for the window object
    - the third parameter is the window attributes

    So for the record, just use ANYTHING alphanumeric for the second parameter, and you WILL be sorted.


  • Registered Users Posts: 6,464 ✭✭✭MOH


    Still broken in IE6


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    OK, I'm definitely not getting something...

    On the promotional.html page, the code is as follows for the script:
    <script language="javaScript" type="text/javascript">
    			<!--
    			function popup_window(url,w,h)
    			{
    			var width=w;
    			var height=h;
    			var from_top=350;
    			var from_left=500;
    			var toolbar='no';
    			var location='no';
    			var directories='no';
    			var status='no';
    			var menubar='no';
    			var scrollbars='yes';
    			var resizable='yes';
    			var atts='width='+width+'height='+height+',top='+from_top+',toolbar='+toolbar;			atts+=',location='+location+',directories='+directories+',status='+status;
    atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
    			window.open(url,brochurerequest,atts);
    			}
    			-->
    </script>
    

    and the execution command (tied to the button and CLICK HERE text) is:
    <a href="javascript: popup_window("brochurerequest.html",500,500)">[i]insert text or image here[/i]</a>
    

    Now it won't work on the Promotional page in Firefox at all.

    HOWEVER, I left well enough alone for the index.html home page as it is on its own (separate from the template), and its code is:
    <script language="javaScript" type="text/javascript">
    			<!--
    			function popup_window(url,w,h)
    			{
    			var width=w;
    			var height=h;
    			var from_top=350;
    			var from_left=500;
    			var toolbar='no';
    			var location='no';
    			var directories='no';
    			var status='no';
    			var menubar='no';
    			var scrollbars='yes';
    			var resizable='yes';
    			var atts='width='+width+'height='+height+',top='+from_top+',screenY=';
    			atts+= from_top+',left='+from_left+',screenX='+from_left+',toolbar='+toolbar;
    			atts+=',location='+location+',directories='+directories+',status='+status;
    			atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
    			window.open(url,"brochure-request.html",atts);
    			}
    			-->
    </script>
    </head>
    

    and the execution command (in 'Catalogue Request' in the footer) is:
    <a href="javascript: popup_window('brochurerequest.html',500,500)">Catalogue Request</a>
    

    And it works in Firefox etc. but probably not in IE7 or below.

    Stumped,

    Seanie.


  • Moderators, Science, Health & Environment Moderators Posts: 8,870 Mod ✭✭✭✭mewso


    See this line:-

    window.open(url,brochurerequest,atts);

    change it to:-

    window.open(url,"brochurerequest",atts);

    It's been said several times above. The second parameter is s string name for the window you are opening. As a string it must be in inverted commas or a string var.


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    Mad_Max wrote: »
    Take the hyphon out of the page name
    Remove show from your atts
    Remove screenX and screenY from atts too

    This works for me in IE (5.5,6,7,8) FF3, Chrome and Opera 9.
    var atts='width='+width+',height='+height+',top='+from_top+',';
    atts+= from_top+',left='+from_left+',toolbar='+toolbar;			
    atts+=',location='+location+',directories='+directories+',status='+status;		
    atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;		
    
    window.open(url,'brochurerequest',atts);
    

    They way you've defined atts just made it hard to decipher what was going on.

    Edit: ScreenX and ScreenY options aren't the main cause, the hyphon is I believe but still if they're not in the spec then no point using them


    Phew, I knew I wasn't dreaming the last day or two completely.

    Dude I pasted code AND tested it in all relevant browsers for you. It worked, still does and probably still will.

    As mentioned above you need to put quotes around the name argument in the window.open method NOT the popup_window method.

    Change this:
    <a href="javascript: popup_window(" brochurerequest.html="" ,500,500)="">
    

    Wherever you have done it to:
    <a href="javascript: popup_window('brochurerequest.html' ,500,500)">
    

    and then step back from the pc ;)


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Seanie M wrote: »
    OK, I'm definitely not getting something...

    On the promotional.html page, the code is as follows for the script:
    <script language="javaScript" type="text/javascript">
    			<!--
    			function popup_window(url,w,h)
    			{
    			var width=w;
    			var height=h;
    			var from_top=350;
    			var from_left=500;
    			var toolbar='no';
    			var location='no';
    			var directories='no';
    			var status='no';
    			var menubar='no';
    			var scrollbars='yes';
    			var resizable='yes';
    			var atts='width='+width+'height='+height+',top='+from_top+',toolbar='+toolbar;			atts+=',location='+location+',directories='+directories+',status='+status;
    atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
    			window.open(url,[b][u]"brochurerequest"[/u][/b],atts);
    			}
    			-->
    </script>
    

    Include the quotes around brochurerequest, making it "brochurerequest"

    In the same way as url is a variable, brochurerequest would be a variable; but "brochurerequest", including the quotes, is the string, which is what's required.

    To clarify 100% - avoiding ANY possible confusion from all of the posts so far - the ONLY issue with your ORIGINAL code was the fact that the same parameter had a hyphen and a dot/period in it.



    Of course, if you'd copy and pasted the code that I'd posted,
    window.open(url,"newWindow",atts);
    

    ...or the code that Max posted
    window.open(url,'brochurerequest',atts);
    

    Then that would have worked first time; AFAIK, you could have even left in the screenX and screenY parameters, although they only applied to Netscape 4+ and are therefore irrelevant; top and left do the trick in all modern browsers.

    To simplify matters, just replace the entire function with the following:
    function popup_window(url,w,h) {
    	var atts='width='+w+'height='+h+',top=350,left=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
    	window.open(url,"brochurerequest",atts);
    }
    


  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Too many cooks, confuses me sometimes! I also realised I was using double quotes at one time for the execution command when I should have been using single quotes... D'uh!

    Now, I have done the changes, and all seems fine in the browsers I have here. Roll on someone with IE7 and below please...


  • Registered Users Posts: 1,322 ✭✭✭Mad_Max


    You won't believe it but... it works ;):D:D


  • Registered Users Posts: 6,464 ✭✭✭MOH


    Fine now in IE6


  • Advertisement
  • Registered Users Posts: 1,795 ✭✭✭Seanie M


    Thanks folks, very much appreciated! If I can return the favour at all...

    Seanie.

    :)


Advertisement