Reputation: 39
I would like to open a new tab (or window, depending on the user's browser settings) with javascript when the user clicks on a link. I have seen other sites who do that, without being flagged as popups by firefox. My link is flagged as a popup though. Maybe it's because it is necessary that the domain stay the same (which is not my case) ? Is there a way to prevent my link to be flagged as popup, seeing as the new tab event is triggered by a mouse click ?
Thanks
Upvotes: 0
Views: 946
Reputation: 183290
What I would probably do -- depending on the exact requirements -- is, instead of setting an onclick
handler, set an onmouseup
handler, and instead of having the handler open the link, have the handler set the link's href
-- and not override the browser's default behavior. (That last part isn't actually important behavior-wise, since there's no major default on-mouse-up behavior, but it's important readability-wise!) Then, after the handler finishes, the browser will act just as if the user had clicked on a normal link with that href
: assuming typical Firefox settings, a left-click will open the link in the same tab, a middle-click will open it in a new tab, and a right-click will open a context-menu with options such as "Open Link in New Window" and "Open Link in New Tab".
Upvotes: 0
Reputation: 8283
A really simple solution if it's just going to be you using it is allowing popups on that site. You can configure firefox like so: http://malektips.com/firefox_0003.html
Upvotes: 0
Reputation: 413720
You can use the "target" attribute of the link itself:
<a target=_blank href='whatever'>Click Me!</a>
to open a link in a new window/tab.
Upvotes: 1