Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Disable right click context menu in a pop up window.

  1. #1
    Join Date
    Jul 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Disable right click context menu in a pop up window.

    Hi Everyone,

    I'm somewhat new to Javascript. Today I added "larger image view" pop up windows to my online art gallery. The problem I'm having is I'm not sure how to disable the right click context menu in those pop up windows. I don't want to disable it for the rest of my site, just within the pop up menus themselves. Do you know of a script or a line of code that I could add to do this?

    I'd really appreciate your help.

    Thanks!!

    ~Rivian

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This isn't a foolproof script by any means, there are many ways around it. But, if you are determined to use it, put the code to block the right click on the page where you want it active. If there is no page (as could be the case with an image only popping up in a new window), make one.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm not sure I entirely understand what you mean by make one.... How is it possible to make an entirely separate page for a pop up that I only want to call when someone clicks a thumbnail image so that they can see the larger version.

    Can you explain what you mean and maybe give me an example? Is there a script to call pages like that?

    Thanks,
    ~Rivian

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, the most direct and cross browser friendly way is to make a page for each image. Here is a demo of another approach:

    Opener
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I definitely appreciate the idea... the problem I have with it is that I have over 400 images . If I were to make a page for each one not only would it take me forever, but it would use up sizable resources. Is there another way?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Did you check out the demo? There is but one page used to display all of the three different images. Anyways, if you cannot work it from there, I am afraid I am not much interested, as I think the whole idea of no right click is stupid to begin with. It won't protect anything and doesn't provide any visual benefit either. My time is better spent helping others.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jul 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    I haven't disabled right click on any other portion of my site and have instead chosen to use other protection methods. I understand that many people have issues with disabling the context menu and I feel very much the same way. I just really want to disable it for my pop ups because I can't see how I can make any of my other security measures work in the pop up scenario that I already have. I was really hoping that there would be a snippet of code that I could add to my javascript to make this function properly.

    I've seen other sites manage this somehow and I'm hoping that I can do the same. If anyone has any ideas, please, post a message. I'm desperate to do this for my artists so that they can have an easy to use interface and at the same time offer some measure of protection, even if it is easily circumvented by those who know how.

    Thanks,
    ~Rivian

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Rivian
    I've seen other sites manage this somehow . . .
    Name one. It is an illusion. They may have disabled right click in IE but, that doesn't protect their content.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jul 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking I fixed it!

    Ok, so I answered my own question and for anyone else who comes across this problem, here's the fix.

    <script type="text/javascript">

    // JK Pop up image viewer script- By JavaScriptKit.com
    // Visit JavaScript Kit (http://javascriptkit.com)
    // for free JavaScript tutorials and scripts
    // This notice must stay intact for use

    var popbackground="black" //specify backcolor or background image for pop window
    var windowtitle="Larger View" //pop window title

    function detectexist(obj){
    return (typeof obj !="undefined")
    }

    function jkpopimage(imgpath, popwidth, popheight, textdescription){

    function getpos(){
    leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
    toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
    if (window.opera){
    leftpos-=screenLeft
    toppos-=screenTop
    }
    }

    getpos()
    var winattributes='width='+popwidth+',height='+popheight+',resizable=no,left='+leftpos+',top='+toppos
    var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
    if (typeof jkpopwin=="undefined" || jkpopwin.closed)
    jkpopwin=window.open("","",winattributes)
    else{
    getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
    jkpopwin.moveTo(leftpos, toppos)
    jkpopwin.resizeTo(popwidth, popheight+30)
    }
    jkpopwin.document.open()
    jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em" onBlur="self.close()" onClick="self.close()" onContextmenu="return false;"><meta http-equiv="imagetoolbar" content="no"><br>'+textdescription+'</body></html>')
    jkpopwin.document.close()
    jkpopwin.focus()
    }
    </script>

    The piece that I highlighted in orange is a snippet of code that I added to my script. This is all it took to disable the right click in my pop up ONLY. The rest of my page continues to use right click normally. YAY!!!

    I wanted to thank you, John, for helping me. It pushed me to seek out my own solution and I really appreciate that!

    ~Rivian

  10. #10
    Join Date
    Jul 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A simpler way I guess would be to put a hidden image and onclick popup I dunno just a thought.

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
  •