我的目標是使用Firefox的Greasemonkey擴展,但我的問題是,我想選擇/訪問的元素加載爲在menu.html
從a
的值更改爲d
陣列options
內框架。在一個框架中選擇元素
我一直在試圖解決這個問題一段時間,如果somone能夠幫助我,我會非常高興。
我有兩個文件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>
很好看是這樣的:
+----------------------------+
| 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
幀已經被棄用多年了......你爲什麼首先需要幀? – charlietfl
謝謝你的評論。我不是該原始代碼的作者,也沒有能力更改代碼以刪除框架。 – Clone