关于firefox中iframe对象内DOM对象的获取
已有 1829 次阅读2009-11-8 14:49
|个人分类:杂感|系统分类:单片机
关于firefox中i对象内DOM对象的获取
在firefox中i的属性可以采用.getElementById实现,但是DOM对象却不能通过此方式获得。中间很多人提到了跨域访问的问题。我个人觉得不应当是这个问题,而应当是属于对象获取的问题。
i对象当认为是一个DOM window窗口后,应.self.document对象可以获得内部的DOM结构。
示例文件:
1.status.xul
2.1.html
3.btn1.js
btn1.js
button1()
{
alert("button1 on ");
domain = "1.html";
title = contentview.title;
var name = contentview.name;
var window = contentview.self;
var doc = document;
title = "node ";
var btn2 = doc.getElementById("btn2");
var label = btn2.label;
btn2.label = "lalala";
btn2.text ="123";
btn2.name = "456";
btn2.innerHTML = "789";
}
1.html
<html>
<titie>this s test </title>
<body>
<h1>妹妹的一天</h1>
<p>早上吃早点,中午约会吃饭,下午K歌,晚上和哥哥瞎折腾</p>
<button id = "btn2" label="node2" oncommand = "button1()">this test</button>
</body>
</html>
status.xul
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="statswindow" title="狗蛋的偷菜之旅">
<vbox flex="1">
<hbox id="toppanel">
<label value="Enter a URL:"/>
<textbox id="url" flex="1" value="http://wap.kaixin001.com"/>
<button label="Go!"/>
</hbox>
<deion value="Current page:"/>
<hbox flex="1">
<i id="contentview" src="1.html" flex="2">
< language="java" src="btn1.js">
</>
</i>
<vbox>
<groupbox>
<caption label="Stats"/>
<grid flex="1">
<columns>
<column flex="1"/>
<column flex="1"/>
</columns>
<rows>
<row>
<label value="Word count"/>
<textbox class="count" id="wordcount" value="N/A" readonly="true"/>
</row>
<row>
<label value="Character count"/>
<textbox class="count" id="charcount" value="N/A" readonly="true"/>
</row>
<row>
<label value="Element count"/>
<textbox class="count" id="elemcount" value="N/A" readonly="true"/>
</row>
</rows>
</grid>
</groupbox><hbox id="1">
<button id = "btn1" label="add tree node" oncommand = "button1()"></button>
</hbox>
<hbox>
<tree rows="6" flex="1">
<treecols>
<treecol id="nameColumn" label="Name" flex="1"/>
<treecol id="addressColumn" label="Address" flex="2"/>
</treecols>
<treechildren>
<treeitem container="true" open="true">
<treerow>
<treecell label="Guys"/>
</treerow>
<treechildren>
<treeitem>
<treerow>
<treecell label="Bob"/>
<treecell label="Carpenter"/>
</treerow>
</treeitem>
<treeitem>
<treerow>
<treecell label="Jerry"/>
<treecell label="Hodge"/>
</treerow>
</treeitem>
</treechildren>
</treeitem>
</treechildren>
</tree>
</hbox>
<spacer flex="1"></spacer>
</vbox>
</hbox>
</vbox>
</window>