Is there any way to prevent page load of images with javascript?

mikeyla85

I'd like to build a lazy loading plugin. Some resources have indicated that as soon as a src is defined on an image, the browser begins to load it. At what point in page processing does this happen? Is it possible to code in some javascript that prevents this from happening?

Slava Knyazev

If I understood correctly that you do not want to load an image until the user interacts somehow, this is what you might be looking for.

Jsfiddle: http://jsfiddle.net/z2kgpL37/

<img id="myImg" src="" width="107" height="98">


<button onclick="myFunction()">Load image</button>

<script>
function myFunction() {
    document.getElementById("myImg").src = "http://www.w3schools.com/jsref/compman.gif";
}
</script>

If this helped, accept the answer :)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery function load reloads the whole page

来自分类Dev

Error message showing when page load

来自分类Dev

jQuery trigger() on page load does not work

来自分类Dev

Is there a way to look for a flag in a man page?

来自分类Dev

Is there any way to avoid sub queries?

来自分类Dev

通过javascript PageMethods调用WebMethod时会触发Page_Load

来自分类Dev

Ajax load page without refresh

来自分类Dev

Page_Load触发多次?

来自分类Dev

An easy way to prevent hack by changing DOM in browser?

来自分类Dev

How to hide a column in devexpress gridview on page load?

来自分类Dev

Making my background images load faster

来自分类Dev

Any way to parse Less in .net?

来自分类Dev

ServerClick事件触发Page.Load

来自分类Dev

如何在page_load中添加JavaScript

来自分类Dev

I am using okhttp in my android application. Is there any way to prevent duplicate requests from getting executed?

来自分类Dev

How to load external Javascript file in MVC 5 _Layout Page

来自分类Dev

Is there any way to get the page numbers in a PDF of a search pattern?

来自分类Dev

.load return page fragment

来自分类Dev

QWebEngineView在load()或page()方法上崩溃

来自分类Dev

Page_Load()是否可以异步

来自分类Dev

离开页面时调用Page_Load

来自分类Dev

如何拆分page.load上的数据?

来自分类Dev

Prevent Javascript from redirecting

来自分类Dev

通过javascript PageMethods调用WebMethod时会触发Page_Load

来自分类Dev

Is there any way to block javascript pop-overs in Firefox or Chrome?

来自分类Dev

Any way to interpret pstree?

来自分类Dev

延迟javascript $(window).load

来自分类Dev

C#中的javascript函数Page_Load

来自分类Dev

Is there any way to install a transient package?

Related 相关文章

热门标签

归档