0

Dynamic Async iFrameメソッドを使用しようとしていますが、コードが機能せず、何が間違っているのか混乱しています。iFrame 自体は読み込まれていますが、期待される Web ページが表示されません。私が何を意味するか見てください。

これが私のコードです。私は何を間違っていますか?

<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_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 %>
4

1 に答える 1

1

Domの準備ができたら、このjqueryを試してiframeをロードしてください

$(document).ready( function(){
   $('#placeholder').html('<iframe src=""></iframe>');
})

ID=placeholder のプレースホルダーがあると仮定します。

またはすべてがロードされたとき(画像を含む)

$(window).load( function(){
   $('#placeholder').html('<iframe src=""></iframe>');
}) 
于 2013-09-10T04:35:31.040 に答える