Is it possible to catch the attribute of hyperlink with JavaScript or Jquery on browsers open new tab event?
lets say I have a hyperlink <a href="http://example.com/something">MyLink</a> and using right click on link and opening new tab should alert first “http://example.com“
Ok, so this is the best that I can come up with but it ain’t pretty.
Have all the links on the page point to another page (we’ll call it redir.html). redir.html is passed a parameter via the URL that defines what page it should then open, like
redir.html?page=www.example.com/something. redir.html then executes whatever JavaScript you want, perhaps only if it was opened in a new tab/window. This can be detected by checking to see ifwindow.history.length === 1.redir.html:
Example anchor tag on source page:
(I got the
getParameterfunction from this SO post.)