Jump to content

Recommended Posts

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?

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.

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.

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.

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.

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.

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.

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. ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.