如何禁用右键点击页面/弹出窗口打开在Iframe使用javascript/jquery的超链接
How to disable right click on a hyperlink in page/popup open in Iframe using javascript/jquery?
我需要禁用右键点击一个锚标签/超链接在页面/使用javascript/jquery在iframe打开弹出窗口?
我有下面的代码逻辑,当我在iframe打开页面,但不工作,当我打开iframe弹出框点击链接在iframe页面
在下面的示例中,当我右键单击打开弹出窗口链接时,它不允许右键单击,但当我通过单击打开弹出窗口链接打开弹出窗口时,它不适用于弹出窗口中的链接。
有什么建议吗?
下面的示例代码片段供参考-
TestPage.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<title>Test Page</title>
</head>
<body>
<iframe id="sampleIframe" src="PopupPage.html" width="400" height="150"></iframe>
<script language="javascript" type="text/javascript">
$('#sampleIframe').load(function() {
$('#sampleIframe').contents().find('a').each(function() {
$(this).on("contextmenu", function() {
return false;
});
});
});
</script>
</body>
</html>
PopupPage.html
<html>
<head>
<title>Popup Page</title>
</head>
<body>
You are on popup page.
<a href="javascript:openPopup();">Open Popup</a>
<script language="javascript" type="text/javascript">
function openPopup() {
window.open("LinkPage.html", null,
"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
</script>
</body>
</html>
LinkPage.html
<html>
<head>
<title>Link Page</title>
</head>
<body>
<a href="www.Google.com">Goto Google</a>
<a href="www.facebook.com">Goto Facebook</a>
</body>
</html>
要做到这一点,您需要在中包含脚本来禁用实际iFrame内容中的链接。
为了演示,使用以下代码创建一个jsfiddle (它不允许我保存它以发布链接)这将是你的"LinkPage.html"
HTML<a href="javascript:openPopup();">Open Popup</a>
JAVASCRIPT function openPopup() {
window.open("http://jsfiddle.net/t45qvtap/1/show", null,
"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
你会看到它在工作。
为了进一步解释,这是上面代码将在iFrame中打开的文件的内容,这将是你的"PopupPage.html" HTMLThis content is in an iframe
<div>
<a href="www.Google.com">Goto Google</a>
<a href="www.facebook.com">Goto Facebook</a>
</div>
JAVASCRIPT $('body').contents().find('a').each(function() {
$(this).on("contextmenu", function() {
return false;
});
});
相关文章:
- 使用jQuery从原始页面内容创建iframe
- 如何使用Angular动态添加iframe-src
- 是否可以使用iframe API在iOS浏览器上播放youtube视频
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- 对特定的iframe使用javascript书签
- 在不设置协议的情况下,使用javascript/jquery更改iframe-src
- 什么更好?使用iframe或jQuery之类的东西在外部网站中加载HTML文件
- 如何在使用JavaScript或jQuery刷新父页面后保留iframe-src
- 当#在iFrame中使用HTML时,阻止页面移动
- 使用php脚本验证访问者的年龄,并在不刷新的情况下根据结果加载iframe
- Javascript-->iframe使用postMessage方法调整大小
- 如何通过iframe使用函数
- 在打开的窗口中对iframe中的iframe使用getElementById
- iFrame使用正则表达式Javascript将Mainpage与其他内容区分开来
- 防止iframe使用jquery保持焦点
- 如何获得一个iframe关闭后打开另一个iframe使用Jquery
- 如何打印pdf在iframe使用javascript在ie6
- 可以't在为iframe使用createElement时设置allowTransparency
- 如何禁用右键点击页面/弹出窗口打开在Iframe使用javascript/jquery的超链接
- 父级jquery不被iframe使用