Jump to content

onMouseOver problems


umekille78

Recommended Posts

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...