【发布时间】:2017-04-16 22:23:07
【问题描述】:
我的目标是在 Firefox 中使用 Greasemonkey 扩展名将数组 options 中的 menu.html 中的值从 a 更改为 d,但 我的问题是我想要的元素选择/访问作为框架加载。
我已经尝试解决这个问题一段时间了,如果有人能帮助我,我会非常高兴。
我有两个文件main.html 和menu.html,其内容是:
main.html(是主页)
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<script language="javascript">
document.writeln("<frameset rows='89,*,15' border='0' frameborder='0' framespacing='0'>");
// here is the menu frame
document.writeln("<frame src='menu.html' name='menufrm' frameborder='no' border='0' scrolling='no' target='_self' marginwidth='0' marginheight='0' noresize>");
document.writeln("</frameset>");
</script>
</head>
</html>
menu.html(“通过”帧加载)
<html>
<head>
<meta http-equiv='Pragma' content='no-cache'>
<link rel=stylesheet href='stylemain.css' type='text/css'>
<script language='javascript' src='menuBcm.js'></script>
<base target="_self">
</head>
<body class='mainMenuBody' topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="0" cellspacing="0" height="1000">
<tr>
<td class='menu' width="170" valign="top" align="left">
<script language='javascript'>
var options = new Array('a',
'b',
'c');
// ultimate goal is to change the value of a to d above before
// execution of the script below
createBcmMenu(options); // from menuBcm.js
initializeDocument();
</script>
</td>
</tr>
</table>
</body>
</html>
Wich 看起来像这样:
+----------------------------+
| main page (192.168.1.1) |
| |
| +---------------------+ |
| | frame (192.168.1.1) | |
| +---------------------+ |
| |
+----------------------------+
Greasemonkey 脚本:
// ==UserScript==
// @name a-to-d
// @namespace namespace
// @include http://192.168.1.1/main.html
// @include http://192.168.1.1/menu.html
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
var newScript = `var options = new Array('d','b','c');` ;
// somehow select that element below
document.(!).innerHTML = newScript; // (!): somehow select script element in menu.html
【问题讨论】:
-
框架已被弃用多年......为什么首先需要框架?
-
感谢您的评论。我不是该原始代码的作者,也没有能力更改代码以删除框架。
标签: javascript greasemonkey frames tampermonkey