admin管理员组文章数量:1320915
I would like to have a "Load More" button that displays all the content of a div
tag when clicked. It's important that all external resources within this content (such as images, JavaScripts, iframes, etc.) are fetched by the browser not immediately on each page load, but only after the user clicks the button.
I believe this can be achieved by first removing the content div
from the DOM and then adding it back on button click, but I am not sure how to do that. Can someone please help me? Thank you!
I'd like to mention that the content div
can be quite large (several kilobytes), so it needs to be located in the HTML code (as shown in the code below), rather than in the JS code. It will also be dynamic, constantly changing.
Alex
function load_more() {
document.getElementById('content_div').style.display = 'block';
}
<html>
<body>
Content here...<br><br>
<div style='display: inline-block; border: 1px solid black; padding: 10px; cursor: pointer' onclick='load_more()'>Load More</div><br><br>
<div id='content_div' style='display: none'>
More dynamic content here, including external images, scripts, and even iframes. These should NOT be automatically retrieved by the browser immediately on each page load, as they currently are with this code alone. Instead, they should only be fetched after the button above is pressed. So, if the user loads the page but does NOT click the button, no external resources will be retrieved by the browser.
</div>
</body>
</html>
本文标签: javascriptLoad external resources only on button clickStack Overflow
版权声明:本文标题:javascript - Load external resources only on button click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742001541a2411112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论