请问一个iframe相互调用dom的有关问题
请教一个iframe相互调用dom的问题
代码如上
点击按钮则禁用掉iframe中的右键菜单和选中.
问题是兼容firefox,以及当我在test中增加一个更改iframe的src属性就会使得禁用失效的问题
------解决方案--------------------
document.getElementById("aaa").src = "b.htm";
//页面重新加载了,将你的事件处理函数定义在onload事件函数内.
document.getElementById("aaa").onload=function(){
window.frames["aaa"].document.oncontextmenu=...){};
}
------解决方案--------------------
firefox不支持onselectstart事件,禁止选择用css控制,而且要在iframe onload中设置
[code=text][/code]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>子页面禁止选中/复制,不兼容firefox</title>
</head>
<body>
<script type="text/javascript" >
function test() {
window.frames["aaa"].document.oncontextmenu = new Function("return false;");
window.frames["aaa"].document.onselectstart = new Function("event.returnValue=false");
}
</script>
<iframe id="aaa" name="aaa" src="b.htm" height="800" width="800"></iframe>
<input type=button onclick="test()" value="aaa" />
</body>
<script type="text/javascript">
</script>
</html>
代码如上
点击按钮则禁用掉iframe中的右键菜单和选中.
问题是兼容firefox,以及当我在test中增加一个更改iframe的src属性就会使得禁用失效的问题
[code=text][/code]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>子页面禁止选中/复制,不兼容firefox</title>
</head>
<body>
<script type="text/javascript" >
function test() {
document.getElementById("aaa").src = "b.htm";
window.frames["aaa"].document.oncontextmenu = new Function("return false;");
window.frames["aaa"].document.onselectstart = new Function("event.returnValue=false");
}
</script>
<iframe id="aaa" name="aaa" src="b.htm" height="800" width="800"></iframe>
<input type=button onclick="test()" value="aaa" />
</body>
<script type="text/javascript">
</script>
</html>
------解决方案--------------------
document.getElementById("aaa").src = "b.htm";
//页面重新加载了,将你的事件处理函数定义在onload事件函数内.
document.getElementById("aaa").onload=function(){
window.frames["aaa"].document.oncontextmenu=...){};
}
------解决方案--------------------
firefox不支持onselectstart事件,禁止选择用css控制,而且要在iframe onload中设置
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>子页面禁止选中/复制,不兼容firefox</title>
</head>
<body>
<script type="text/javascript" >
function addEvent(){
var doc=document.getElementById("aaa").contentWindow.document;
doc.oncontextmenu = function(){parent.document.title=new Date().getTime();return false}
doc.onselectstart = function(){return false}
var style=document.createElement('style');
style.type='text/css';
doc.getElementsByTagName('head')[0].appendChild(style);
if (style.styleSheet) style.styleSheet.cssText += '-moz-user-select:none';
else style.innerHTML += 'body{-moz-user-select:none}';
}
function test() {
var a=document.getElementById("aaa");
a.src = "1.html";
}
</script>
<iframe id="aaa" name="aaa" src="1x.html" height="800" width="800" onload="addEvent()"></iframe>
<input type=button onclick="test()" value="aaa" />
</body>
</html>