我打算用书签插入一段js,然后操作一个frameset的网页,<frameset rows="105,*" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="../include/flattop.htm" name="topFrame" frameborder="no" scrolling="no" noresize marginwidth="0" marginheight="0">
<frameset cols="125,*" frameborder="NO" border="0" framespacing="0">
<frame src="sdtleft.aspx" name="leftFrame" frameborder="no" scrolling="no" noresize marginwidth="0" marginheight="0">
<frame src="../newsboard/newsinside.aspx" name="main" frameborder="no" scrolling="auto" marginwidth="0" marginheight="0">
</frameset>
</frameset>它有三个frame,我用下页的标签代码插入到每个frame中,包括document本身
javascript: (function () {
jsCode = document.createElement('script');
jsCode.setAttribute('src', 'http://localhost/load.js');
document.body.appendChild(jsCode);
for(var x=0; x<window.frames.length;x++){
jsCode = document.createElement('script');
jsCode.setAttribute('src', 'http://localhost/load.js');
window.frames[x].content.document.body.appendChild(jsCode);
}
}());
然后我在http://localhost/load.js中测试,比如写console.log(self.document.URL);
它返回了四次(正确),但是URL都是window.document.URL,而我预想的是
window.frames[x].content.document.URL
x = 0,1,2难道这样插入js以后,它还是以整个窗口为对象运行的,而非以每个frame作为基础运行么?我用的是firefox + firebug这个程序本来是想模仿chrome插件中的"all_frames": true(在每个frame中运行)功能的,救助,是否有解?
<frame src="../include/flattop.htm" name="topFrame" frameborder="no" scrolling="no" noresize marginwidth="0" marginheight="0">
<frameset cols="125,*" frameborder="NO" border="0" framespacing="0">
<frame src="sdtleft.aspx" name="leftFrame" frameborder="no" scrolling="no" noresize marginwidth="0" marginheight="0">
<frame src="../newsboard/newsinside.aspx" name="main" frameborder="no" scrolling="auto" marginwidth="0" marginheight="0">
</frameset>
</frameset>它有三个frame,我用下页的标签代码插入到每个frame中,包括document本身
javascript: (function () {
jsCode = document.createElement('script');
jsCode.setAttribute('src', 'http://localhost/load.js');
document.body.appendChild(jsCode);
for(var x=0; x<window.frames.length;x++){
jsCode = document.createElement('script');
jsCode.setAttribute('src', 'http://localhost/load.js');
window.frames[x].content.document.body.appendChild(jsCode);
}
}());
然后我在http://localhost/load.js中测试,比如写console.log(self.document.URL);
它返回了四次(正确),但是URL都是window.document.URL,而我预想的是
window.frames[x].content.document.URL
x = 0,1,2难道这样插入js以后,它还是以整个窗口为对象运行的,而非以每个frame作为基础运行么?我用的是firefox + firebug这个程序本来是想模仿chrome插件中的"all_frames": true(在每个frame中运行)功能的,救助,是否有解?
解决方案 »
- 关于parent.opener的问题???????????????????????
- JS创建的控件,当用户返回时都不存在了
- [推荐]这个网站的js应用做得不错,学习借鉴
- extjs form success的函数调用不了??
- js如何操作cookies
- 做好的js脚本图片切换特效自己可以看但是其他电脑看图片是叉叉请大家帮助
- 如何在OnKeyUp事件中知道用户按下的哪一个键?
- 求javascript类似delay的函数
- 怎么不让event.returnValue显示默认对话框?
- 怎样设置select的缺省值?急!
- 如何自动过滤非手机号和小灵通号码
- 如何给元素的onmousedown加上jquery里定义的函数?
只要把 window.frames[x].content.document.body.appendChild(jsCode);
改成 window.frames[x].document.body.appendChild(jsCode);
就可以附加到每个frame中了