Skip to main content
Participant
December 14, 2022
Question

Right click opens URL, how to prevent?

  • December 14, 2022
  • 1 reply
  • 93 views

Hello, everyone,

 

I created an HTML5 banner with a button to a website. If I click the left button, the page opens. But the same thing happens when i right-click with the Mouse - I never saw this behavior before, how can you prevent this?

 

I use:

 

this.button_link_to_site.addEventListener("click", fl_ClickToGoToWebPage);

function fl_ClickToGoToWebPage() {
window.open("https://www.adobe.com", "_blank");
}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 14, 2022

this.addEventListener("mousedown",clickF);


function clickF() {
var e = window.event;
if(window.event.which==1){
// left click. check for hittest and dispatch window.open if desired
} else if(window.event.which==3){
// right click
}

}

this.addEventListener("mousedown",rightclick);