在Chrome中,< embed>触发$(document).ready()时不加载资源。为什么? [英] In Chrome, <embed> resource isn't loaded when $(document).ready() is triggered. Why?

查看:47
本文介绍了在Chrome中,< embed>触发$(document).ready()时不加载资源。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FF和IE中,当调用 $(document).ready()时,将检索SVG(SVG)文档。

In FF and IE, the SVG (SVG) document is retrieved when $(document ).ready() is called.

在Chrome中, getSVGDocument $(文档).ready()时返回null调用。 (虽然它似乎在大约7ms之后找到它,如 setTimeout 所示。)

In Chrome, the getSVGDocument returns null instead when $(document ).ready() is called. (Although it seems to find it approx 7ms after, as shown by the setTimeout.)

为什么Chrome不能在 $(文档).ready()的时刻找到加载的< embed> SVG文档,但FF和IE做?

Why does Chrome not find the loaded <embed> SVGdocument at moment of $(document ).ready(), but FF and IE do?

(我不想使用 setTimeout(7ms)只是等待Chrome抓住up !!!因为那是......跛脚。)

(I don't want to have to use a setTimeout(7ms) just to wait for Chrome to catch up!!! Because that's... lame.)

下面的代码简单代码显示了场景:FF + IE中的 RETURNS SVGDocument (除非对 getSVG()的调用延迟7ms !!!)。

The code simple code below shows scenario: RETURNS SVGDocument in FF + IE RETURNS NULL in Chrome (unless the call to getSVG() is delayed by 7ms!!!).

注意:此代码需要在Chrome的 localhost 服务器上运行;这是一个单独的Chrome问题。

N.B: This code needs to be run on localhost server with Chrome; that is a separate Chrome issue.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<script>

    getSVG = function () {

        var el = document.getElementById("embedId");

        SVGDoc = el.getSVGDocument();

        console.log(SVGDoc);                           // returns null in Chrome

    }



    $(document).ready(function () {

        getSVG();                        

        //setTimeout("getSVG()", 7);      // this works, showing that Chrome is NOT "ready"

    });


</script>

</head>

<body>

<embed id="embedId" src="man.svg" type="image/svg+xml" width="50" height="50"/> 

</body>

</html>


推荐答案

试试这个

$(window).load(function(){
    console.log($('#embedId')[0].getSVGDocument());
});

另一种可能的解决方案:

Another possible solution:

$(function(){
    var a = $('#embedId')[0];

    a.addEventListener("load",function(){

        //do stuff with 'a'

    },false);
});

这篇关于在Chrome中,&lt; embed&gt;触发$(document).ready()时不加载资源。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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