umekille78 Posted April 28, 2006 Share Posted April 28, 2006 Hi all!Im very new to JS so please be patient with me I have a HTML/PHP page with this JS code att the top: <script>var PicFlag = false;function onpic(){ PicFlag = true;}function offpic(){ PicFlag = false;}function click(){ if (event.button==2 && PicFlag == false) { alert('Rightclick is not permitted') }}document.onmousedown=click</SCRIPT> Later in the same document a php function prints: <IMG SRC='http://www.sf.se/clayton/gfx/sfbio_logo.gif' onMouseOver=onpic onMouseOut=offpic> The purpose of this is to enable right clicking on the picture but no where else.Anyway. The code dont work. And becouse Im no good at JS i dont get why. Can any one help me?/Per Link to comment Share on other sites More sharing options...
scott100 Posted April 28, 2006 Share Posted April 28, 2006 incorrect: onMouseOver=onpic onMouseOut=offpiccorrect: onMouseOver="onpic()" onMouseOut="offpic()"Should work ok now, you forgot the parenthasis and quotes <head><script>var PicFlag = false;function onpic(){ PicFlag = true;}function offpic(){ PicFlag = false;}function click(){ if (event.button==2 && PicFlag == false) { alert('Rightclick is not permitted') }}document.onmousedown=click</SCRIPT></head><body> <IMG SRC='http://www.sf.se/clayton/gfx/sfbio_logo.gif' onMouseOver="onpic()" onMouseOut="offpic()"></body> You can also access the context menu from the keyboard, just so you are aware. Link to comment Share on other sites More sharing options...
umekille78 Posted April 28, 2006 Author Share Posted April 28, 2006 Thancs Scott100 you are a true life saver Link to comment Share on other sites More sharing options...
umekille78 Posted April 28, 2006 Author Share Posted April 28, 2006 You can also access the context menu from the keyboard, just so you are aware.<{POST_SNAPBACK}> 2 smal questions.1: How do you acsess the menu from the key bord?2: How do you disable that option?/Per Link to comment Share on other sites More sharing options...
scott100 Posted April 28, 2006 Share Posted April 28, 2006 I know of two ways you can access it through the keyboard press the context menu key on the keyboard (it's the one immediately to the left of the right CTRL key) hold down the shift key and press F10 To disable <body oncontextmenu="return false;"> Link to comment Share on other sites More sharing options...
umekille78 Posted April 28, 2006 Author Share Posted April 28, 2006 To disable <body oncontextmenu="return false;"> <{POST_SNAPBACK}> Hi again!That works. The problem is that is alsow disables the right click options on the pictures I wanted to have.Any ideas?/Per Link to comment Share on other sites More sharing options...
scott100 Posted April 28, 2006 Share Posted April 28, 2006 My thoughts are this: <body oncontextmenu="return false;"> <IMG SRC='http://www.sf.se/clayton/gfx/sfbio_logo.gif' onmouseover="document.body.oncontextmenu='return true;'" onmouseout="document.body.oncontextmenu='return false;'"></body> The only problem is with mouseout Link to comment Share on other sites More sharing options...
umekille78 Posted April 28, 2006 Author Share Posted April 28, 2006 Thanks again!You are the best at helping./Per Link to comment Share on other sites More sharing options...
ben3001 Posted April 28, 2006 Share Posted April 28, 2006 hmm in my opinion i think its pretty pointless in having this function, simply becuase on firefox you can right click view page info and then click media, and all your images on the page are displayed.then scroll through the images and click save as. Link to comment Share on other sites More sharing options...
Kosher Kid Posted April 28, 2006 Share Posted April 28, 2006 perhaps i'm doing something wrong...i cut and pasted scott's code, created an html file and opened it in both firefox and ie. in both cases, i was able to right click and choose save image as.what's the dealio? Link to comment Share on other sites More sharing options...
Kosher Kid Posted April 28, 2006 Share Posted April 28, 2006 sorry to reply to my own reply but here's the behavior i'm getting in both firefox and ie:when i copied scott's original code, right click on the logo still worked.when i added the oncontext menu to the body tag, the right click did not work.when i added the last piece of code to disable the context menu but enable right click on the image, right click still did not work in firefox and produced a "right click is not permitted" message in ie.i guess i'm confused. btw, it's firefox 1.5.0.2 and ie 6.0 w/sp1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now