简体   繁体   English

Javascript似乎不适用于框架集中包含html标签的html页面

[英]Javascript doesn't seem to work for html page with html tags inside framesets

I want to run the following JavaScript on a site with no <body> tag and it consists of <framesets> to nest documents. 我想在没有<body>标记的网站上运行以下JavaScript,它由<framesets>以嵌套文档。

document.onclick= function(event) {
    if (event===undefined)
        event= window.event;
    var target = 'target' in event ? event.target : event.srcElement;
    alert("clicked");
};

The HTML document I am dealing with is quite bizarre as I've never seen anything like this. 我正在处理的HTML文档非常奇怪,因为我从未见过这样的事情。 Anyhow, the JavaScript will not run but no error message is shown. 无论如何,JavaScript将无法运行,但不会显示错误消息。 Firebug returns only the HTML xPath, not the entire/html/frameset/frame/html/body/div/a, so I can see there is some problem with having frameset tags. Firebug仅返回HTML xPath,而不返回整个/ html / frameset / frame / html / body / div / a,因此我可以看到使用frameset标签存在一些问题。 Note I have no control over the target site I am supposed to test. 请注意,我无法控制要测试的目标站点。

<html>
    <head>
        <title>weird site...</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="IE=EmulateIE8" http-equiv="X-UA-Compatible">
    </head>
    <frameset frameborder="0" border="0" framespacing="0" cols="*,796,*">
        <frame scrolling="no" noresize="noresize" src="/main/left.php" name="links" style="background-color: transparent;">
            <html>
                <body>
                    <div>
                        <a>text</a>
                    </div>
                    ....
                </body>
            </html>
        </frame>
        <frameset frameborder="0" border="0" framespacing="0" rows="58,*">
            <frame scrolling="no" noresize="noresize" marginheight="0" marginwidth="0" src="/main/top.php" name="oben" style="background-color: transparent;">
                <html>
                    <body>....</body>
                </html>
            </frame>
            <frameset frameborder="0" border="0" framespacing="0" cols="116,680">
                <frame scrolling="no" noresize="noresize" marginheight="0" marginwidth="0" src="/main/login.php" name="persoenliches" style="background-color: transparent;"></frame>
                <frame scrolling="auto" noresize="noresize" marginheight="0" marginwidth="0" src="/main/index.php" name="mitte" style="background-color: transparent;"></frame>
            </frameset>
        </frameset>
        <frame scrolling="no" noresize="noresize" src="/main/right.php" name="heartbeat"></frame>
        <noframes></noframes>
    </frameset>
</html>

Where are you putting your Javascript code? 您要将Javascript代码放在哪里? Remember that each different frame is an independent page, containing separate windows (global variables) and documents so you can't write an event handler in one place and expect it to work for everyone. 请记住,每个不同的框架都是一个独立的页面,其中包含单独的windows (全局变量)和documents因此您不能在一个地方编写事件处理程序并期望它对每个人都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM