IE6/7 GetAttribute Get href/src Property (relative path 0 value differs from other browsers _javascript tips

Source: Internet
Author: User
The test code is as follows:
Home <script> var link = document.getelementsbytagname (' a ') [0]; var img = document.getelementsbytagname (' img ') [0]; Alert (Link.getattribute (' href ')); Alert (Img.getattribute (' src ')) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

There are elements A and IMG (standard document mode), and a relative path is set. The browser effects are as follows

IE6/7: Return to full path

Ie8/9/10/firefox/safari/chrome/opera: Returns a relative path

If you want to be consistent with other browsers in Ie6/7, you can set the second argument for GetAttribute to 2.

Home <script> var link = document.getelementsbytagname (' a ') [0]; var img = document.getelementsbytagname (' img ') [0]; Alert (Link.getattribute (' href ', 2)); Note the second parameter alert (img.getattribute (' src ', 2)); Note the second parameter </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The standard getattribute method is not to define the second parameter, the magic ie AH. The following is an MSDN description of the setattribute parameter

Related:

Http://msdn.microsoft.com/en-us/library/ms536429%28v=VS.85%29.aspx

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.