Hello all! I have a javascript running on my site at http://www.kayoss.net that disables right clicking (viewing source, saving pictures, etc.) that works beautifully in IE...but not in Firefox. Does anyone know of a solution?

Dani AI

Generated

A few quick points specific to this thread that should get the page unstuck: is seeing IE-only behavior because older IE and Firefox use different event models and handler conventions. was right to flag the missing event argument; was pointing to the inline shortcut; and correctly called out text-property differences when you manipulate content. A more robust, unobtrusive approach avoids inline attributes and handles both models.

Use a small cross-browser listener that prevents the context menu where supported. Put it where it runs after the document is ready (end of body or DOMContentLoaded):

(function(){
  function blockContext(e){
    e = e || window.event;
    if (e.preventDefault) e.preventDefault();
    else e.returnValue = false;
    return false;
  }

  if (document.addEventListener) document.addEventListener('contextmenu', blockContext, false);
  else if (document.attachEvent) document.attachEvent('oncontextmenu', blockContext);
  else document.oncontextmenu = blockContext;
})();

If Firefox still "doesn't work," open the browser console and look for script errors (syntax errors will stop subsequent handlers). Also confirm the script runs after the DOM exists. If your code reads or writes node text, use feature detection (prefer textContent when present, fallback to innerText) to avoid the cross-browser property trap mentioned.

A final caution: this technique is easily bypassed (DevTools, keyboard shortcuts, saving images via URL) and can harm usability and accessibility. For anything you truly need to protect, use server-side measures or watermarking for images rather than relying on client-side blocking.

Recommended Answers

All 6 Replies

1st, the script calls for an argument to be passed in, it appears to be the Event object, yet your call doesn't pass anything in.

Also, the script definition should properly be inside the head section. Lastly, it's a bad idea, in my opinion, to attempt to alter or change the user model.

Disabling right click is done using a single statement.

<body oncontextmenu="return false;">

This works for both the mouse and the keyboard in all modern browsers except Opera (which doesn't allow you to block right click).

It is a known problem that that Javascript will behave different with various browsers. On of the way is to use javascript that is generally accepted by W3 standards. If some functions still do not work, try hiding the script from that browser to avoid any errors.

Thank you,
Ryan

Some JavaScript Functions Are not Working in FireFox Browser.
I want to Know what is the reason why it is not working ?

Some JavaScript Functions Are not Working in FireFox Browser.
I want to Know what is the reason why it is not working ?

One common reason is that the script is using a property which is not available in that browser.

For example: innerText vs. textContent.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.