Investigation of onerror events supported by scripts

Source: Internet
Author: User

I have a requirement that the dynamically created script tag should be removed in any case. There are four available options: onload, ontimeout, and onerror. Therefore, we need to check whether the browser supports onerror events. Confirmed by the naked eye, IE6 ~ Both opera11 and 8 are not supported. Safari, chrome, Firefox, and ie9 are supported. However, opera cannot be programmed to detect support for opera (with high finger points in my power ).

</P> <p> var El = document. createelement ("script"); <br/> document. body. insertbefore (El, null); <br/> var name = "onerror" <br/> alert (name in El); <br/> el. setattribute (name, ""); <br/> alert (typeof El [name] = "function"); <br/> el. onerror = function () {<br/> alert ("onerror events supported") <br/>}< br/> el. src = "test _" + 1 * new date; <br/> setTimeout (function () {<br/> var parent = el. parentnode <br/> If (parent & parent. nodetype = 1) {<br/> If (El. clearattributes) {<br/> el. clearattributes (); <br/>}else {<br/> el. onerror = NULL; <br/>}< br/> parent. removechild (EL) <br/> El = Name = NULL; <br/>}< br/>}, 2000) </P> <p>

RunCode

Seeing that ie678 and opera are just a living treasure, I really want to cut the opera guys!

Now we can only use this code to differentiate:

 
// By situ zhengmei var suppscripscripterror = (! Window. Opera) &-[1,];

Related link: checks the browser's support for events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.