Skip to content Skip to sidebar Skip to footer

Javascript Tweak To Open Url Either In A New Window Or New Tab Based On User's Choice

I am facing an issue where a link on my website opens in a new window if you simply click on it. However, if you right click and say open in new window or new tab, it opens the sam

Solution 1:

I would suggest doing something like this.

Setup an event handler to capture when a user right clicks. When they do, run you function to get the selfServSite url, and set the links href attribute to be the new Url.

here is some info on capturing the right click event.

How can I capture the right-click event in JavaScript?

EDIT: Based on our discussion in the comments, here is a revised solution.

When the page is opened in a new window from a right-click, it has "#id-card" appended to it, so what you need to do is check for that value when the page first loads, and if it's there, run the same javascript function that gets run when the user left-clicks on the link.

You can check for this value using the location objects hash property. http://www.w3schools.com/jsref/obj_location.asp

Post a Comment for "Javascript Tweak To Open Url Either In A New Window Or New Tab Based On User's Choice"