首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >动态异步iframe故障

动态异步iframe故障
EN

Stack Overflow用户
提问于 2013-09-10 00:36:51
回答 1查看 2.4K关注 0票数 0

我正在尝试使用动态异步iFrame方法,但我的代码不起作用,我对自己做错了什么感到困惑。iFrame本身正在加载,但它没有显示预期的网页。见我的意思是

这是我的密码。我做错了什么?

代码语言:javascript
运行
复制
<script>
    (function(d){
        var iframe = d.body.appendChild(d.createElement('iframe')),
            doc = iframe.contentWindow.document;

        // style the iframe with some CSS
        iframe.style.cssText = "width:900px;height:600px;";

        doc.open().write('<body onload="' + 
            'var d = document;d.getElementsByTagName(\'head\')[0].' + 
            'appendChild(d.createElement(\'script\')).src' + 
            '=\'http://www.uab.edu/dining/locations\'">');

        doc.close(); //iframe onload event happens

    })(document);
</script>

编辑:解决方案代码

代码语言:javascript
运行
复制
<%= javascript_tag do %>
        $(window).load( function(){
            window.map = '<%= j @college.map.html_safe %>';
            window.street_view = '<%= j @college.street_view.html_safe %>';
            window.food = '<%= j @college.food.html_safe %>';
            window.housing = '<%= j @college.housing.html_safe %>';
            window.weather = '<%= j @college.weather.html_safe %>';
            $('#map').html(map);
            $('#street_view').html(street_view);
            $('#food_iframe').html(food);
            $('#housing_iframe').html(housing);
            $('#weather_section').html(weather);
        });
    <% end %>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-10 04:35:31

当Dom准备好时,尝试使用这个jquery加载iframe

代码语言:javascript
运行
复制
$(document).ready( function(){
   $('#placeholder').html('<iframe src=""></iframe>');
})

假设你有ID=placeholder的位置持有者。

或当全部加载时(包括图像)

代码语言:javascript
运行
复制
$(window).load( function(){
   $('#placeholder').html('<iframe src=""></iframe>');
}) 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18709096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档