iframe 加载事件

发布于 2024-11-05 23:38:47 字数 696 浏览 0 评论 0原文

我有一个具有如下结构的页面;

<body onLoad="LoadPage()">
        <iframe src="pg1.html">
      <p>Your browser does not support iframes.</p>
    </iframe>
    <iframe src="about:blank">
      <p>Your browser does not support iframes.</p>
    </iframe>
    </body>

现在,在主体负载上,我为第二个 iframe 设置了“src”值。 如果我调用 body onload,该函数似乎被调用两次...那么有没有其他方法可以调用该函数来设置 src..

<script type="text/javascript"> 
        function LoadPage(){
            var pdfVal = document.forms[0].pdf_val.value;
            document.getElementById('ipad_pdf_link').href = pdfVal; 
        }
        </script>

I have a page which has the structure like this;

<body onLoad="LoadPage()">
        <iframe src="pg1.html">
      <p>Your browser does not support iframes.</p>
    </iframe>
    <iframe src="about:blank">
      <p>Your browser does not support iframes.</p>
    </iframe>
    </body>

Now on body load, I set the "src" value for the 2nd iframe.
If I call body onload, the function seems to be getting called twice...So is there any other way by which I can call the function to set the src..

<script type="text/javascript"> 
        function LoadPage(){
            var pdfVal = document.forms[0].pdf_val.value;
            document.getElementById('ipad_pdf_link').href = pdfVal; 
        }
        </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑寡妇 2024-11-12 23:38:47

我不知道为什么它会加载两次,但是您可以使用 jQuery,而不是在 onLoad 上执行此操作:

<script> 
function loadPage() {
    var pdfVal = $("name=[pdf_val]").val();
    $('#ipad_pdf_link').attr("src", pdfVal); 
}

$(function() { // called when the page finishes loading
    loadPage();
});
</script>

jQuery 在处理浏览器差异方面更加强大,我确信将为您节省未来还有很多令人头疼的事情。

参考:

I'm not sure why it loads twice, but you can, instead of doing it on the onLoad, use jQuery:

<script> 
function loadPage() {
    var pdfVal = $("name=[pdf_val]").val();
    $('#ipad_pdf_link').attr("src", pdfVal); 
}

$(function() { // called when the page finishes loading
    loadPage();
});
</script>

jQuery is much more robust to handle browser differences and i'm sure will save you a lot of headaches in the future.

Reference:

挖个坑埋了你 2024-11-12 23:38:47

你可以把它放在

<script type="text/javascript"> 
    LoadPage();
</script>

HTML 的底部,而不是放在 onload 事件上,当页面加载完成时它仍然会被调用。

You could put

<script type="text/javascript"> 
    LoadPage();
</script>

At the bottom of the HTML, instead of on the onload event, and it will still get called when the page has finished loading.

优雅的叶子 2024-11-12 23:38:47

加载两次很可能与此有关:
http://msdn.microsoft.com /en-us/library/ie/hh180173%28v=vs.85%29.aspx

我有一种情况,当使用 。我们有一个系统,旧的 asp 页面在 iframe 中运行,并且有数十个。它们都使用相同的旧语法。第一个 init 调用正确,但第二个调用是在最顶层完成的。这基本上把事情搞砸了,因为在 iframe window.top 中没有应该有的功能,因为它是 iframe 窗口本身。在 IE8、IE9 的 IE8 模式、Chrome 和 Firefox 中工作正常。

Loading twice is most likely related to this:
http://msdn.microsoft.com/en-us/library/ie/hh180173%28v=vs.85%29.aspx

I have a case where IE9 calls init function twice, when it is set with <body onload="x()">. We have a system, where our old asp-pages run in iframe, and there are dozens of them. All of them use the same old syntax. First init call is made correctly, but the second one is done as top-most. This basically messes things up, because in the iframe window.top does not have functions that there should be, because it is the iframe window itself. In IE8, IE9's IE8 mode, Chrome and Firefox it works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文