推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
arbipher

embed 元素内嵌的#document 怎么通过 JavaScript 获取它的 document

  •  
  •   arbipher · Apr 30, 2014 · 5907 views
    This topic created in 4399 days ago, the information mentioned may be changed or developed.
    <embed>
    __#document
    ____<!DOCTYPE html>
    ____<html>
    ______<body>
    ______</body>
    ____</html>
    </embed>

    我能获取到embed元素。(没记错的话,embed元素是不能有子元素的,)其childNodes()返回空列表[]。

    用Chrome调试台,强行修改body的属性,给加了一个onclick="console.log('cheating');",有效果。

    请教下,有什么方法能获得内嵌的DOM的document。

    P.S.
    大坑渗入,挂了两天。这个游戏修改之后,发现坑太大,弃了。
    http://www.acfun.com/a/ac1146409
    这个问题就是改这个游戏发现的。
    5 replies    2014-04-30 17:56:48 +08:00
    sanddudu
        2
    sanddudu  
       Apr 30, 2014
    感觉这样是跨域操作
    chrome会直接拒绝,如果是纯webkit应该是是允许的,我在用node-webkit写应用的时候改过iframe里的css
    arbipher
        3
    arbipher  
    OP
       Apr 30, 2014
    @marrow
    这个帖子都搜到过,不work

    > document.embeds[0]
    <embed width=​"1024" height=​"960" //blabla

    > document.embeds[0].getSVGDocument()
    null

    > document.embeds[0].contentDocument
    undefined


    @sanddudu
    我在调试模式里面是可以修改的啊,而且我给body加了onclick函数,这个函数就生效了。
    我想知道为什么调试模式就可以改。。。
    marrow
        4
    marrow  
       Apr 30, 2014
    啊不好意思刚才那个没试过就发上来了
    刚才跑了一下属性
    Object.getOwnPropertyNames(document.embeds[0]).filter(function(a){return document.embeds[0][a] ;})
    发现 document.embeds[0].ownerDocument
    就可以拿到
    arbipher
        5
    arbipher  
    OP
       Apr 30, 2014
    @marrow
    这个返回的是外面的document吧。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1060 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 18:38 · PVG 02:38 · LAX 11:38 · JFK 14:38
    ♥ Do have faith in what you're doing.