zulfi
zulfi

Reputation: 113

Disable keys and mouse click on iframe in Mozilla

I have applied this code for iframe id.

 <iframe id='<?php echo 'fraDisabled'.$i.$post->ID; ?>' src='<?php echo $file['url']; ?>'  ></iframe >


function disableContextMenu()
{

  var text="you dont have proper privelages to do this !!";
  window.frames['<?php echo 'fraDisabled'.$i.$post->ID; ?>'].document.oncontextmenu = function(){alert(text); return false;};
  window.frames['<?php echo 'fraDisabled'.$i.$post->ID; ?>'].document.onkeypress = function(){alert(text); return false;}; 
  window.frames['<?php echo 'fraDisabled'.$i.$post->ID; ?>'].document.onmousedown = function(){alert(text); return false;}; 
}

PHP:

<iframe id='<?php echo 'fraDisabled'.$i.$post->ID; ?>' src='<?php echo $file['url']; ?>'>
</iframe>

It works in Chrome but it is not working in Mozilla Firefox.

Upvotes: 1

Views: 791

Answers (1)

freefaller
freefaller

Reputation: 19953

Probably won't help that you have an apostrophe ' in your text variable.

Change...

var text='sorry you don't have permission to do this !!';

To...

var text='sorry you don\'t have permission to do this !!';

Or...

var text="sorry you don't have permission to do this !!";

ADDITIONAL

You also need to change the ''id'' in the last 2 lines to just 'id'

UPDATE

Looks like an issue with Firefox and the use of windows.frames['id'] when the frame only has an id.

Try adding the dynamic id you're generating to both the id and name attributes on the <iframe>.

YET ANOTHER PIECE OF INFORMATION HAS COME TO LIGHT

I've just discovered that the <iframe> in question will contain a PDF document.

It would appear that Chrome will fire the click and context menu events as the OP is expecting... but IE and Firefox do not, which is more the behaviour I would expect.

Unfortunately I do not believe there is anything you can do about it. And from a usability point of view, you are also making it impossible to scroll on the PDF using the scroll bar (mouse wheel would still work though).

I still believe that the name attribute is required in FireFox for the window.frames reference though.

Upvotes: 2

Related Questions