This is not possible I'm afraid. When you're inside the iframe, you're in a second <html><body> tag... Unless you own what's inside the iframe and are able to put your Javascript on the page within then it's impossble. iframes are very limited for many many
security reasons.
HTH's
Regards,
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
I just had an idea - if you overlay a div over the top of the iframe, (of the top of my head: div with margin-top: - <the height of the iframe> and then put the onclick event to that div... it MIGHT work... I'm not sure... it will most likely render the
iframe useless actually...
I'm not sure it's possible
Regards,
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
Arun Neon
0 Points
7 Posts
Capture mouse right click event inside a iframe using jquery.
Jun 27, 2012 09:21 AM|LINK
Hi all,
I need to capture right mouse click event inside a iframe in asp.net using any javascript or jquery codes.
below is the code i have tried so far.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Detect IFrame Clicks</title> <script type="text/javascript" language="javascript" src="JScript/jquery-1.7.1.js"></script> <script type="text/javascript" language="javascript" src="JScript/jquery.ui.core.js"></script> <script type="text/javascript" language="javascript" src="JScript/jquery.ui.widget.js"></script> <script type="text/javascript" language="javascript" src="JScript/jquery.ui.mouse.js"></script> <script type="text/javascript"> var Event; document.onmousedown = onMousebtClick var isOverIFrame = false; $(document).ready(function() { function processMouseOut() { /*log("IFrame mouse >> OUT << detected.");*/ isOverIFrame = false; top.focus(); } function processMouseOver() { /*log("IFrame mouse >> OVER << detected.");*/ isOverIFrame = true; } function processIFrameClick() { if (isOverIFrame) { // replace with your function log("IFrame >> CLICK << detected. "); onMousebtClick(); } } function log(message) { var console = document.getElementById("console"); var text = console.value; text = text + message + "\n"; console.value = text; } function attachOnloadEvent(func, obj) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', func, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener('load', func, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', func); } else { if (typeof window.onload == 'function') { var oldonload = onload; window.onload = function() { oldonload(); func(); }; } else { window.onload = func; } } } function init() { var element = document.getElementsByTagName("iframe"); for (var i = 0; i < element.length; i++) { element[i].onmouseover = processMouseOver; element[i].onmouseout = processMouseOut; } if (typeof window.attachEvent != 'undefined') { top.attachEvent('onblur', processIFrameClick); } else if (typeof window.addEventListener != 'undefined') { top.addEventListener('blur', processIFrameClick, false); } } attachOnloadEvent(init); }); function onMousebtClick() { switch (event.button) { case 1: alert("leftclick"); break; case 2: alert("right click"); break; } } /*document.onmousedown = onMousebtClick*/ </script> </head> <body id="mybody"> <iframe src="http://www.microsoft.com" width="800px" height="300px" id="ifrm"> </iframe> <br /> <br /> <form name="form" id="form" action=""> <textarea name="console" id="console" style="width: 300px; height: 300px;" cols="" rows=""></textarea> <button name="clear" id="clear" type="reset"> Clear</button> </form> </body> </html>i can able to detect right mouse click in body tag but i can't able to detect the right mouse click event inside the iframe.
Can anyone please help me.
JQuery javascript Iframe
BoogleC
Contributor
2208 Points
445 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jun 27, 2012 09:30 AM|LINK
This is not possible I'm afraid. When you're inside the iframe, you're in a second <html><body> tag... Unless you own what's inside the iframe and are able to put your Javascript on the page within then it's impossble. iframes are very limited for many many security reasons.
HTH's
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
Arun Neon
0 Points
7 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jun 27, 2012 09:47 AM|LINK
Thanks for your reply. i need to solve that issue. if you get any idea in future please reply to this.
BoogleC
Contributor
2208 Points
445 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jun 27, 2012 09:52 AM|LINK
Hey,
I just had an idea - if you overlay a div over the top of the iframe, (of the top of my head: div with margin-top: - <the height of the iframe> and then put the onclick event to that div... it MIGHT work... I'm not sure... it will most likely render the iframe useless actually...
I'm not sure it's possible
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
Arun Neon
0 Points
7 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jun 27, 2012 10:01 AM|LINK
Hi,
I can't able get your point. Please put some sample code for my better understanding.
Is any replacement is there for iframe in asp.net ? :)
Song-Tian - ...
All-Star
43699 Points
4304 Posts
Microsoft
Re: Capture mouse right click event inside a iframe using jquery.
Jul 02, 2012 06:44 AM|LINK
Hi,
Please refer to the code as follow:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jquery_rightclick.aspx.cs" Inherits="asp_jquery_rightclick" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <div id="div1" style="background-color:Red; height:120px"> </div> </form> <script type="text/javascript"> $('#div1').mousedown(function (event) { switch (event.which) { case 1: alert('Left mouse button pressed'); break; case 2: alert('Middle mouse button pressed'); break; case 3: alert('Right mouse button pressed'); break; default: alert('You have a strange mouse'); } }); </script> </body> </html>Feedback to us
Develop and promote your apps in Windows Store
BoogleC
Contributor
2208 Points
445 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jul 02, 2012 10:59 AM|LINK
He can capture the right-click no problem - he is trying the impossible of capturing the right-click WITHIN an IFRAME.
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
asteranup
All-Star
30184 Points
4906 Posts
Re: Capture mouse right click event inside a iframe using jquery.
Jul 02, 2012 11:02 AM|LINK
Hi,
Check this-
http://forums.asp.net/p/1737637/4676456.aspx/1?Re+GRIDVIEW+CELL+MOUSE+LEFT+CLICK+AND+RIGHT+CLICK+EVENTS+IN+JAVASCRIPT+FUNCTIONALITY
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog