admin管理员组文章数量:1355574
I need to capture right mouse click event inside a iframe in asp 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">
document.onmousedown = onMousebtClick
var isOverIFrame = false;
$(document).ready(function() {
function processMouseOut() {
isOverIFrame = false;
top.focus();
}
function processMouseOver() {
isOverIFrame = true;
}
function processIFrameClick() {
if (isOverIFrame) {
log("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="" 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.
I need to capture right mouse click event inside a iframe in asp 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">
document.onmousedown = onMousebtClick
var isOverIFrame = false;
$(document).ready(function() {
function processMouseOut() {
isOverIFrame = false;
top.focus();
}
function processMouseOver() {
isOverIFrame = true;
}
function processIFrameClick() {
if (isOverIFrame) {
log("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." 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.
Share Improve this question asked Jun 27, 2012 at 9:32 ArunArun 1,7049 gold badges26 silver badges41 bronze badges2 Answers
Reset to default 5It is possible if the page inside an iframe
is on the same domain.
IFrame page at same domain: http://fiddle.jshell/rathoreahsan/MNtw8/8/show/
See Demo: http://jsfiddle/rathoreahsan/gJtkW/
While if you access the page of an other domain inside an iframe
like you are doing then it is not remended.
Edited: See some references given below, hope it will be helpful.
the-iframe-cross-domain-policy-problem
cross-domain-iframe-resizing
Hey: this might help:
How Enable Right Click in IFRAME with JavaScript
or
http://forums.asp/p/1818670/5042726.aspx/1?Capture+mouse+right+click+event+inside+a+iframe+using+jquery+
This is not possible I'm afraid. When you're inside the iframe, you're in a second 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.
Please let me know if anyone thinks otherwise, happy to take this post off.
Although Try this hack mentioned here: http://www.codingforums./archive/index.php/t-8824.html
or here http://forums.mozillazine/viewtopic.php?f=19&t=371334
cheers,
本文标签: javascriptCapture mouse right click event inside a iframe using jqueryStack Overflow
版权声明:本文标题:javascript - Capture mouse right click event inside a iframe using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743931446a2563915.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论