Javascript Event for “Open in new Tab”

﹥>﹥吖頭↗ 提交于 2020-01-01 09:17:10

问题


I have the following problem: I use Javascript onclick event to change href of a link. It works like a charm but only if user just clicks a link. If "Open in new tab" feature is used for the link - onclick event will not fire and href will never change. Is there any way to handle such an event? Perhaps with jQuery or some other JS Framework?

Example:

<a href="some_url" onclick="this.href = 'some_other_url'">Link</a>

回答1:


Try to change

<a href="some_url" onclick="this.href = 'some_other_url'">Link</a>

to

<a href="some_url" onmousedown="this.href = 'some_other_url'">Link</a>


来源:https://stackoverflow.com/questions/12365339/javascript-event-for-open-in-new-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!