选择框架中的元素 [英] Select element in a frame

查看:99
本文介绍了选择框架中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用Firefox中的Greasemonkey扩展名将menu.html中数组options中的值从a更改为d,但是 我的问题是我尝试使用的元素选择/访问被加载为框架 .

My goal is to change a value from a to d inside the array options in menu.html using Greasemonkey extension in Firefox but my problem is that the element I am trying to select/access is loaded as a frame.

一段时间以来,我一直在努力解决这个问题,如果有人能帮助我,我将感到非常高兴.

I have been trying to solve this issue for some time now and I would be very happy if somone could help me out.

我有两个文件main.htmlmenu.html,它们的内容是:

I have got two files main.html and menu.html whose contents are:

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 

推荐答案

您可以使用window.frames.menufrm

然后执行以下操作:

var frm = window.frames.menufrm;    
frm.options = ['d','b','c'];
frm.createBcmMenu(options);

不能保证再次调用该函数会很好,但是在该框架加载之前,您不能进行任何更改,并且原始函数调用已经运行

No guarantees that calling the function again will work well but you can't change anything before that frame has loaded and the original function call will have already been run

这篇关于选择框架中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆