We help IT Professionals succeed at work.

javascript

yadav bake
yadav bake asked
on
80 Views
Last Modified: 2017-11-21
how to stop user to open multiple tab in browser when user hit web site URL
Comment
Watch Question

Software Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Are you trying to prevent right click so users cannot open multiple tabs by clicking on links on your website?

You could do that using javascript but again, this will not work if javascript is turned off in browser settings -

document.addEventListener("contextmenu", function(e){
    e.preventDefault();
}, false); 

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Any javascript solution can be circumvented.
Prakash SamariyaIT Professional
CERTIFIED EXPERT
Top Expert 2015

Commented:
Workaround:
- Remove direct URL reference
- Implement JS function to open requested URL in current window

<script>
function showMe(url)
{
	window.location.href=url;
}
</script>

Open in new window

In HTML, Replace below code (your url links)
<a href="your url">Your Text</a>

Open in new window

with as per below code like:
<a href="#" onclick="showMe('your url')">Your Text</a>

Open in new window

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.