The relative path and absolute path for js to read href values in IE

Source: Internet
Author: User

The property value for reading the href link through JavaScript is that IE sometimes reads the absolute path, while other standard browsers such as Firefox are the original path.

 

In IE, for the getattribute method of JavaScript, ie also provides the second parameter with values 0, 1 and 2. If the value is 2, the original path value is used. If the value is 1, the absolute path of the server is used.

 

Let's take a look at the Code:

 

 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> untitled document </title> <br/> </pead> </P> <p> <body> <br /> <Div id = "test"> <a href = ".. /index. PHP "mce_href =" index. PHP "> test </a> </div> <Div id =" res Ult "> </div> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> var test = document. getelementbyid ('test'); <br/> var link = test. getelementsbytagname ('A'); <br/> linkhref = link [0]. getattribute ('href '); <br/> alert (linkhref); <br/> linkhref = link [0]. getattribute ('href ', 0); <br/> alert (linkhref); <br/> linkhref = link [0]. getattribute ('href ', 1); <br/> alert (linkhref); <br/> linkhref = link [0]. getattribute ('href ', 2); <br/> alert (linkhref); </P> <p> // --> </MCE: SCRIPT> <br/> </body> <br/> </ptml> <br/>

 

Reference: http://www.planabc.net/2008/11/06/ie-href-bug/

 

 

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.