javascript获取iframe文档内容(兼容IE和Firefox)
在网上找到在IE下操作IFrame内容的代码:
document.frames["MyIFrame"].document.getElementById("s").style.color="blue";
但是这在Firefox下无效。
所以,想到在Firefox下用FireBug来调试。经过调试发现在Firefox下可用以下代码来实现:
document.getElementById("MyIFrame").contentDocument.getElementById("s").style.color="blue";
详细代码如下:
TestIFrame.htm:
<html>
<head>
<script type="text/javascript">
function f(){
var doc;
if (document.all){//IE
doc = document.frames["MyIFrame"].document;
}else{//Firefox
doc = document.getElementById("MyIFrame").contentDocument;
}
doc.getElementById("s").style.color="blue";
}
</script>
</head>
<body onload="f()">
<iframe id = "MyIFrame" name = "MyIFrame" src = "MyIFrame.htm" width = "100" height="100">
</body>
</html>
MyIFrame.htm:
相关文档:
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
file://写/成一行
-->
</SCRIPT>
参数解释:
<SCRIPT LANGUAGE="javascript"&g ......
如果你想进一步了解如何用JavaScript来为网页添加交互性的话,你也许已经听过JavaScript的事件代理(event delegation)了,并且会觉得只有那些牛逼烘烘的JavaScript程序员才会关心这样复杂的设计模式。事实上,如果你已经知道怎么样去添加JavaScript的事件处理器(event handler),实现事件代理也是件轻而易举的事情。
J ......
"These memory leaks often
occur as a result of circular references between JavaScript objects and
objects within IE’s DOM (document object model)."
GPDE Team Blog
明显的DOM对象与 JavaScript对象循环引用很好判断,难的是隐含的循环引用判断!
隐含的循环引用需要通过作用域链进行分析判 ......
深入理解Javascript闭包
最近在网上查阅了不少Javascript闭包(closure)相关的资料,写的大多是非常的学术和专业。对于初学者来说别说理解闭包了,就连文字叙述都很难看懂。撰写此文的目的就是用最通俗的文字揭开Javascript闭包的真实面目。
一、什么是闭包?
“官方”的解释是:所谓“闭包 ......