Javascript cool feature of the day: on Browser Ready
I have a nice little one-liner script you can use in your HMTL page to run some a function when the browser is done loading the HTML.
I have been using this cool little snippet for a while, something I factored down for my own purposes, and tucked away in my little bag of tricks. I didn't realize that others' were not using something similar to this, (I saw a spate of posts where people were using document.write)[SHUDDER!]. So, I'm going to post it, and let the world rejoice:
var _my_init = document.addEventListener ? document.addEventListener("DOMContentLoaded", function(){myinit();}, false): setInterval( function(){if (/loaded|complete/.test( document.readyState )){ clearInterval(_my_init);myinit(); } }, 10);
Works in IE, FireFox, and Safari. Probably others, as I think most browsers support one of the two methods for bootstrapping an init function.
To use it, just replace the two myinit() calls with whatever you want to run, and the replace the _my_init variables to something that'll be unique to you. I'd comment on my crazy desire to overload the living tar out of the ternary operator in javascript, but that'd be redundant.
![]() |
|

79 Comments:
8qrxeM The best blog you have!
FEcrQV Good job!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
Magnific!
Wonderful blog.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
Wonderful blog.
lJD9wJ write more, thanks.
Good job!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Wonderful blog.
Magnific!
Good job!
Nice Article.
Nice Article.
Please write anything else!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
Wonderful blog.
Please write anything else!
Good job!
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Thanks to author.
All generalizations are false, including this one.
Build a watch in 179 easy steps - by C. Forsberg.
Suicidal twin kills sister by mistake!
I don't suffer from insanity. I enjoy every minute of it.
What is a free gift ? Aren't all gifts free?
Suicidal twin kills sister by mistake!
All generalizations are false, including this one.
Lottery: A tax on people who are bad at math.
Give me ambiguity or give me something else.
Suicidal twin kills sister by mistake!
What is a free gift ? Aren't all gifts free?
I'm not a complete idiot, some parts are missing!
Hello all!
Thanks to author.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
What is a free gift ? Aren't all gifts free?
Clap on! , Clap off! clap@#&$NO CARRIER
Lottery: A tax on people who are bad at math.
Build a watch in 179 easy steps - by C. Forsberg.
If ignorance is bliss, you must be orgasmic.
Suicidal twin kills sister by mistake!
If ignorance is bliss, you must be orgasmic.
Change is inevitable, except from a vending machine.
Lottery: A tax on people who are bad at math.
Suicidal twin kills sister by mistake!
Clap on! , Clap off! clap@#&$NO CARRIER
When there's a will, I want to be in it.
Thanks to author.
Good job!
A flashlight is a case for holding dead batteries.
Give me ambiguity or give me something else.
640K ought to be enough for anybody. - Bill Gates 81
Suicidal twin kills sister by mistake!
Give me ambiguity or give me something else.
When there's a will, I want to be in it.
Nice Article.
Please write anything else!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
I don't suffer from insanity. I enjoy every minute of it.
Build a watch in 179 easy steps - by C. Forsberg.
Build a watch in 179 easy steps - by C. Forsberg.
What is a free gift ? Aren't all gifts free?
Suicidal twin kills sister by mistake!
Lottery: A tax on people who are bad at math.
Change is inevitable, except from a vending machine.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
Suicidal twin kills sister by mistake!
Change is inevitable, except from a vending machine.
Build a watch in 179 easy steps - by C. Forsberg.
Energizer Bunny Arrested! Charged with battery.
What is a free gift ? Aren't all gifts free?
wow gold cheap wow gold buy wow gold world of warcraft gold wow world of warcraft wow gold WoW Warrior WoW Hunter WoW Rogue WoW Paladin WoW Shaman WoW Priest WoW Mage WoW Druid WoW Warlock power leveling powerleveling wow power leveling wow powerleveling wow guides wow tips google排名 google左侧排名 google排名服务 百度推广 百度排名 网站推广 商业吧 机床 LED灯 电池 塑料 摄像机 移民 甲醇 染料 福州热线 体育博客 股票博客 游戏博客 魔兽博客 考试博客 汽车博客 房产博客 电脑博客 powerlin518 logo design website design web design 商标设计
翻译家和中国翻译协会深圳翻译公司|联合主办,主题为“翻译与多元文化”。这将是国际翻译同声传译在亚洲举行的第一次盛会,是促进亚洲翻译界与国际翻译界交流与合作的大好时机。
广州翻译公司今年广交会不允许外商自带翻译入场,但还是有很多翻译公司|已有生意合作意向的外商,在全国翻译公司中找外语导游当翻译,进行“场外商贸洽谈”。
同声传译现在上海翻译公司英语、日语、法语等大语种导游储备充足,深圳翻译公司|也是随着参加广交会的巴西、西班牙等西班牙语系以及阿拉伯语国家的客商提供深圳翻译大幅增多,小语种导游产生巨大缺口,其中来自巴西的外商比去年多了倍翻译公司
Post a Comment
Links to this post:
Create a Link
<< Home