Jump to content

IE listener problem

Recommended Posts

Hi there, I'm back with one that would again considered a pretty obvious question. I hope not to be too annoying but, on the other hand, I guess it will be easy for you to address this little problem.

Let's say I have a link with id="goo" and I want it to be opened in another tab and leave the current tab unchanged (kinda like doing right click -> open in new tab). And I want to use listeners not handlers. So that's my code so far:

var linkEst ={    init:function()    {        var link = document.getElementById("goo")        if(typeof link.addEventListener != "undefined")        {            link.addEventListener("click", linkEst.oTab, false)        }        else if (typeof link.attachEvent != "undefined")        {            link.attachEvent("onclick", linkEst.oTab)        }    },    oTab:function(event)    {        if(typeof event == "undefined")        {            event = window.event        }        if(typeof event.preventDefault != "undefined")        {            open(this.href)            event.preventDefault()        }        else        {            open(this.href)            event.returnValue = false        }    }}linkEst.init()

Works like a charm in FF, but messes up in IE. IE pops an error: "can't find /path/to/undefined". As soon as I click ok he then follows the link (in the same tab). So I assume that in IE's case, this is not pointing to the actual address, or is the error somewhere else?

As always, thanks in advance for any kind of help or suggestion. I know I can find snippets to achieve the same result, but I'm trying to learn as best as I can.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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