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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...