disable iframes automatic onload

2019-08-01 07:32发布

问题:

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.