欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
The window.onload Problem

The window.onload Problem - Solved!

Well, when I say solved I mean solved for the two most important browsers - Internet Explorer and Mozilla/Firefox. Still that’s good enough isn’t it?

First, let me define the problem. The window.onload event is used by programmers to kick-start their web applications. This could be something trivial like animating a menu or something complex like initialising a mail application. The problem is that the onload event fires after all page content has loaded (including images and other binary content). If your page includes lots of images then you may see a noticeable lag before the page becomes active. What we want is a way to determine when the DOM has fully loaded without waiting for all those pesky images to load also.

Mozilla provides an (undocumented) event tailor-made for this: DOMContentLoaded. The following code will do exactly what we want on Mozilla platforms:

// for Mozilla browsersif (document.addEventListener) {	document.addEventListener("DOMContentLoaded", init, null);}

So what about Internet Explorer?

IE supports a very handy (but non-standard) attribute for the <script> tag: defer. The presence of this attribute will instruct IE to defer the loading of a script until after the DOM has loaded. This only works for external scripts however. Another important thing to note is that this attribute cannot be set using script. That means you cannot create a script using DOM methods and set the defer attribute - it will be ignored.

Using the handy defer attribute we can create a mini-script that calls our onload handler:

<script defer src="ie_onload.js" type="text/javascript"></script>

The contents of this external script would be a single line of code to call our onload event handler:

init();

There is a small problem with this approach. Other browsers will ignore the defer attribute and load the script immediately. There are several ways round this. My preferred method is to use conditional comments to hide the deferred script from other browsers:

<!--[if IE]><script defer src="ie_onload.js"></script><![endif]-->

IE also supports conditional compilation. The following code is the JavaScript equivalent of the above HTML:

// for Internet Explorer/*@cc_on @*//*@if (@_win32)	document.write("<script defer src=ie_onload.js><"+"/script>");/*@end @*/

So far so good? We now need to support the remaining browsers. We have only one choice - the standard window.onload event:

// for other browserswindow.onload = init;

There is one remaining problem (who said this would be easy?). Because we are trapping the onload event for the remaining browsers we will be calling the init function twice for IE and Mozilla. To get around this we should flag the function so that it is executed only once. So our init method will look something like this:

function init() {	// quit if this function has already been called	if (arguments.callee.done) return;	// flag this function so we don‘t do the same thing twice	arguments.callee.done = true;	// do stuff};

And that, as they say, is that.

I’ve provided a sample page that demonstrates this technique. Start copying.

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
在頁(yè)面加載完后執行javascript代碼 --網(wǎng)上download
Mozilla技術(shù)布道者給Web開(kāi)發(fā)人員推薦Firefox插件列表
JavaScript的性能優(yōu)化:加載和執行
推薦幾個(gè)瀏覽器開(kāi)發(fā)工具
HTML中使用JavaScript實(shí)例代碼
瀏覽器開(kāi)發(fā)插件列表(JS、DIV、CSS)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久