SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow disable right click on iframe

    Hello guys ...
    I want to disable right click on an iframe which shows an external url.
    I searched the net for more than a month now and couldn't find any solution you are my last chance ...

    I want to disable right click on whole page even on external iframe like this
    <iframe src="http://google.com" width="600" height="500"></iframe>

    Is their any way?

    Thanks in advanced ...

  2. #2
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out this page: http://www.quirksmode.org/js/improt.html

    But ultimately, even this very well written script is useless, 'cause modern browsers protect its users from usability impairing scripts like disabling the right mouse button.
    I, for one, have disabled such scripts in my browser preferences.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ize Thanks for your reply ...
    I don't know how to apply this to an iframe.
    I want to disable right click on iframe which open an external link outside my server like google.com
    do you understand me ?

  4. #4
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do. But I doubt if it's possible
    You're probably have to disable right click in a Javascript loaded inside the HTML page in the iframe. Which is not possible if the HTML page you're loading comes from outside your server.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can only disable rightclick from within the web page loaded in the frame itself.

    Killing the disable script is much easier as most browsers either provide an option to do it in the browser itself or if they don't a simple one line JavaScript run from the address bar will kill it for an individual page or you can install a userscript to kill it automatically.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    felgall Thanks for your reply, I just wanted to keep newbies away from my links specially that links are out my server ...
    I tried to map an image on all page but it is not working too ... is not their any way to select all page even with iframes inside it ?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Since "no right click" scripts only work when the browser owner gives you access to do so such scripts are rather pointless as few people will knowingly give you access to disable part of their browser and so the code will only work for newbies whose browser is configured incorrectly and who don't know how to fix it.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Brain-storming...

    What if he had one of those one-line "address bar" scripts that could be tacked on to the URL of his iframe source...


    <iframe src="http://google.com/ javascript:disableClick();"></iframe>

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Shaun(OfTheDead) View Post
    Brain-storming...

    What if he had one of those one-line "address bar" scripts that could be tacked on to the URL of his iframe source...


    <iframe src="http://google.com/ javascript:disableClick();"></iframe>
    Most browsers are simply set to disallow any attempt to block access to the context menu from the web page through any means what so ever and so whatever method you try to use will be ignored and the context menu will continue to work from the right mouse button and context menu key on the keyboard as if the script were not there.

    Internet Explorer is the only browser that doesn't provide a browser setting to simply ignore all such scripts. Just makes it a mouse click or two harder to bypass in that browser (assuming that the person is using that browser and trying to access that menu for some reason).

    Also most scripts only block the mouse and still leave the menu accessible from a single key press on the keyboard.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your replies guys ...
    after hard search I found this code which works on IE to disable right click on Iframe but the problem is it does not work with external websites ,,, iframed file must be at the same domain ... take a look on it
    Code:
    <html>
    <head>
    <title>Disable Context Menu</title>
    <script type="text/jscript">
      function disableContextMenu()
      {
        window.frames["fraDisabled"].document.oncontextmenu = function(){alert("No way!"); return false;};   
        // Or use this
        // document.getElementById("fraDisabled").contentWindow.document.oncontextmenu = function(){alert("No way!"); return false;};;    
      }  
    </script>
    </head>
    <body bgcolor="#FFFFFF" onload="disableContextMenu();" oncontextmenu="return false">
    <iframe id="fraDisabled" width="528" height="473" src="local_file.html" onload="disableContextMenu();" onMyLoad="disableContextMenu();"></iframe>
    </body>
    </html>
    I wonder if their is any way to get it work with external urls like google.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •