disable iframes automatic onload

社会主义新天地 提交于 2020-01-05 13:51:10

问题


i have one html with multiple pages in it. i have some pages that i open them in iframes. when i open the html page (it contains all pages in it) it starts loading all iframes and the page becomes so laggy and slowly. is there any way to disable automatic iframes load? or is there any other way to open pages without iframes but still stay in my app? this is my part of my pages (that in one html) code:

<html>
    <head>
    </head>
    <body>
        <div data-role="page" id="website">
            <div data-theme="a" data-role="header">
                <a href="#home" data-theme="a" data-role="button" data-icon="arrow-l" title="back-button">Back</a>                  
                    Idan    
            </div>    
            <div>    
                <iframe src="http://www.idan.com" style="border: 0; position:absolute; top:43px; left:0; right:0; bottom:0; width:320px; height:480px; background: white"></iframe>            
            </div>    
        </div>    
        <div data-role="page" id="website1">
            <div data-theme="a" data-role="header">
                <a href="#home" data-theme="a" data-role="button" data-icon="arrow-l" title="back-button">Back</a>                  
                    Idan    
            </div>    
            <div>    
                <iframe src="http://www.idan1.com" style="border: 0; position:absolute; top:43px; left:0; right:0; bottom:0; width:320px; height:480px; background: white"></iframe>            
            </div>    
        </div>    
        <div data-role="page" id="website2">
            <div data-theme="a" data-role="header">
                <a href="#home" data-theme="a" data-role="button" data-icon="arrow-l" title="back-button">Back</a>                  
                    Idan    
            </div>    
            <div>    
                <iframe src="http://www.idan2.com" style="border: 0; position:absolute; top:43px; left:0; right:0; bottom:0; width:320px; height:480px; background: white"></iframe>            
            </div>    
        </div>
    </body>
    </html>

回答1:


Tom is correct,

put this at the bottom of your html, but before the tag

<script>
document.getElementById("myIframe").src = "http://www.idan1.com";
</script>

you will have to add the id tag to your iframe and remove the src

              <iframe id="myIframe" style="border: 0; position:absolute; top:43px; left:0; right:0; bottom:0; width:320px; height:480px; background: white"></iframe>            

You could even get fancy, and do an set onload.




回答2:


If you set the src attribute of your iframes with javascript you can control at which moment they should load.



来源:https://stackoverflow.com/questions/16715859/disable-iframes-automatic-onload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!