【发布时间】:2011-09-06 05:27:54
【问题描述】:
dv = document.createElement('div'); // create dynamically div tag
dv.setAttribute('id', "lyr1"); // give id to it
dv.className = "top"; // set the style classname
// set the inner styling of the div tag
dv.style.position = "absolute";
// set the html content inside the div tag
dv.innerHTML = "<input id='serialize01' type='button' value='Serialize' onClick='objSerializeDOM.createXML(),objSerializeDOM.disableSerialize()'/>";
// finally add the div id to your form
document.body.insertBefore(dv, document.body.firstChild);
我正在使用这个 javascript 代码在我的域的每个页面上放置一个按钮。我使用 用于 IE 的 GreaseMonkey4IE 插件实现了这一点。但现在的问题是它不适用于具有框架的网页。
file1.html
<html>
<head>
<title></title>
</head>
<frameset rows="50%,50%">
<frame src="friends.html">
</frameset>
</html>
main.html
<html>
<head>
<title>Joe and Jackie's friends</title>
</head>
<frameset cols="25%,75%">
<frame src="file1.html">
</frameset>
</html>
朋友.html
<html>
<head>
<title></title>
</head>
<body bgcolor="#ccffff">
Joe's friend<br>
<b>Bill</b>
</body>
</html>
当我使用 tomcat 部署上述文件时,该按钮未显示。
部署:
1.我复制了上面所有三个 html 文件并将它们粘贴到一个名为 say folder1 的文件夹中。
2.复制tomcat目录下webapps文件夹内的folder1。
3.在 GreaseMonkey4IE 中为域(即)本地主机注册了我的 .js 文件
4.从浏览器(IE8)点击网址,即http://localhost:8080/file1.html(按钮显示)
5.从浏览器点击网址,即http://localhost:8080/main.html(按钮不显示。)
我猜每当网页中有框架时,网页上附加的按钮似乎都会被框架覆盖。 :(
有什么想法吗???
是否可以通过任何方式显示我的按钮??
非常感谢。
【问题讨论】:
-
GreaseMonkey 脚本是否在框架页面上执行?您可以放置警报或控制台输出以进行检查。如果它被执行:执行多少次计数:一次,三,四。每次执行 GM 脚本时检查 window.location.href 的值。 GreaseMonkey 是否将 localhost:8080 理解为与 localhost 相同的域?
-
GreaseMonkey4IE 已经失效了很长一段时间(而且你是唯一一个问这个问题的人)。考虑切换到仍然有支持的东西,比如IE7Pro(也适用于 IE8)。
-
@Andrew 在框架页面上执行 GreaseMonkey 脚本没有问题。 GM 脚本只执行一次。不,GM4IE 不将 localhost:8080 理解为与 localhost 相同的域,它在我编辑域后立即停止工作。最后 window.location.href 给出了我点击的第一个 URL,作为我的脚本也只运行一次。
-
我不确定,但在使用 FRAMESET 向正文添加元素的页面中这是不可能的。对于您的任务,当使用 FRAMSET 加载页面时,您必须枚举所有框架,获取每个框架的文档,并在每个框架->文档上插入您的按钮。或者您必须使用 IFRAME 而不是 FRAME
标签: javascript html iframe greasemonkey frame