Search code examples
javascriptjqueryhtmlinternet-explorer-8href

Can I determine whether clicking a link successfully opened a new window/tab?


I have an <input> element inside an <a> element, meaning IE8 ignores the <a> element's href attribute when clicked. It works fine on all other browsers. Is there a way to determine whether a new tab/window opened? I can then give the user a normal/ugly link to click if it didn't work.

Code example:

<a target="_blank" href="http://somelink.com"><input type="button" class="standard_button_styling" /></a>

What I've tried:

  1. Remove the <input> tag and style the <a> tag: I had trouble making it look just like my other buttons (maybe due to native browser styling) and I don't want it to look worse for everyone to fix a problem with only IE8.
  2. Trigger link with JavaScript window.open(): This doesn't send the referer_url in IE, and the somelink.com in my example relies on it. So I need to have the user click a normal link.
  3. Browser detection: I could just look for IE8 and provide a different response for IE8, but browser detection instead of feature detection is regarded as bad practice and I'd like to avoid it if possible.

Solution

  • You can try to use <button> instead of <input> but I am not sure if this will solve the problem.
    Or just use <form>.

    <form method="get" target="_blank" action="yourlink">
        <input type="submit" value="Click" />
    </form>