document.getElementById("aaa").src = "b.htm";
//页面重新加载了,将你的事件处理函数定义在onload事件函数内.
document.getElementById("aaa").onload=function(){
window.frames["aaa"].document.oncontextmenu=...){};
}
//页面重新加载了,将你的事件处理函数定义在onload事件函数内.
document.getElementById("aaa").onload=function(){
window.frames["aaa"].document.oncontextmenu=...){};
}
<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>