KevinM1 Posted October 15, 2007 Share Posted October 15, 2007 I'm trying to make a link for Adobe Acrobat Reader into a popup. I've gotten it to work in Firefox, but it's not working in IE7. Here's what I have: HTML: ...(requires <a id="popup" href="http://www.adobe.com/products/acrobat/readstep2.html">Adobe Acrobat Reader</a>). JavaScript: var W3CDOM = (document.createElement && document.getElementsByTagName); function init(){ if (!W3CDOM) return; var popup = document.getElementById('popup'); popup.onclick = newWin; } function newWin(evt){ evt = (evt) ? evt : ((event) ? event : null); if(evt){ var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if(elem){ var newWindow = window.open(elem.href, 'Adobe Acrobat Reader 8', 'resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes'); return true; } else{ return false; } } else{ return false; } } window.onload = init; I'm not getting any errors from the console, so it's not a syntax issue. Is there some IE7 quirk that I don't know about? Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/ Share on other sites More sharing options...
KevinM1 Posted October 16, 2007 Author Share Posted October 16, 2007 Apparently I am getting a syntax error in IE7. It's telling me that I have a syntax error on line 18. Unfortunately, that cannot be the case as line 18 is merely 'return false;' (I changed it from 'return true;' in the previous example). However, since the error is about an invalid argument, I'm thinking the problem is on line 17, which is the line that opens the new window. Code: var W3CDOM = (document.createElement && document.getElementsByTagName); function init(){ if (!W3CDOM) return; var popup = document.getElementById('popup'); popup.onclick = newWin; } function newWin(evt){ evt = (evt) ? evt : ((event) ? event : null); if(evt){ var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if(elem){ var newWindow = window.open(elem.href, 'Adobe Acrobat Reader 8', 'resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes'); /* line in question */ return false; } else{ return false; } } else{ return false; } } window.onload = init; Anyone have an idea on what the problem is? Because I'm not seeing it. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370619 Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 JS line number for errors are almost always one line off. elem.href... are you sure that's what you want / it needs? Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370657 Share on other sites More sharing options...
KevinM1 Posted October 16, 2007 Author Share Posted October 16, 2007 JS line number for errors are almost always one line off. elem.href... are you sure that's what you want / it needs? To be honest, I'm not sure. I just want the anchor's URI as the address for the new window. I haven't been able to find any property for it but href in the little relevent documentation I've found online so far. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370666 Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 And that comes back as a string? Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370672 Share on other sites More sharing options...
yzerman Posted October 16, 2007 Share Posted October 16, 2007 why not do this in your html code that sends you to the adobe page - <script language=JavaScript> function newWin(url) { window.open(url,'','width=640,height=500,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no'); } </script> <a href="#" onclick="newWin('http://www.adobe.com/products/acrobat/readstep2.html')">Adobe Acrobat Reader</a> Works great for me across all browsers. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370690 Share on other sites More sharing options...
KevinM1 Posted October 16, 2007 Author Share Posted October 16, 2007 And that comes back as a string? Yup, just tested it with an alert. It outputs the correct URI. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370701 Share on other sites More sharing options...
KevinM1 Posted October 16, 2007 Author Share Posted October 16, 2007 why not do this in your html code that sends you to the adobe page - <script language=JavaScript> function newWin(url) { window.open(url,'','width=640,height=500,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no'); } </script> <a href="#" onclick="newWin('http://www.adobe.com/products/acrobat/readstep2.html')">Adobe Acrobat Reader</a> Works great for me across all browsers. I would, but I absolutely abhor mixing my JavaScript with my markup. It's a very big pet peeve of mine. To me, it's the coding equivalent of scratching one's nails down a chalkboard. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370702 Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 Actually, the second argument can't have spaces... it's the window name, not the title. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370720 Share on other sites More sharing options...
yzerman Posted October 16, 2007 Share Posted October 16, 2007 why not do this in your html code that sends you to the adobe page - <script language=JavaScript> function newWin(url) { window.open(url,'','width=640,height=500,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no'); } </script> <a href="#" onclick="newWin('http://www.adobe.com/products/acrobat/readstep2.html')">Adobe Acrobat Reader</a> Works great for me across all browsers. I would, but I absolutely abhor mixing my JavaScript with my markup. It's a very big pet peeve of mine. To me, it's the coding equivalent of scratching one's nails down a chalkboard. You mean using onclick functions or putting your javascript functions within your HTML page instead of calling on them from another file? Either way, the above works - with about 40 less lines then what you have. Sometimes bigger is not better, just more frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370744 Share on other sites More sharing options...
yzerman Posted October 16, 2007 Share Posted October 16, 2007 Actually, the second argument can't have spaces... it's the window name, not the title. ^^ I think he might be right: http://developer.mozilla.org/en/docs/DOM:window.open#Syntax WindowObjectReference = window.open(strUrl, strWindowName [, strWindowFeatures]); strWindowName This is the string that just names the new window. Such string can be used to be the target of links and forms when the target attribute of an <a> element or of a <form> is specified. This string parameter should not contain any blank space. strWindowName does not specify the title of the new window. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370749 Share on other sites More sharing options...
KevinM1 Posted October 16, 2007 Author Share Posted October 16, 2007 Like you and Fenway suggested, it was the name attribute that tripped me up. For some reason I always think of it as the page title. You mean using onclick functions or putting your javascript functions within your HTML page instead of calling on them from another file? Either way, the above works - with about 40 less lines then what you have. Sometimes bigger is not better, just more frustrating. Like I said, it's a pet peeve of mine. Not a lot of logic behind it, it's just my preferred way of doing things. Quote Link to comment https://forums.phpfreaks.com/topic/73355-solved-problem-with-creating-a-popup-in-ie7/#findComment-370992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.