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