IE6 IE7 userdata local storage.

Source: Internet
Author: User
Tags mootools

I use documentelement as the carrier for local storage of userdata.

Document.doc umentelement. addbehavior ("# default # userdata ");

The tragedy came into being.

 

When the selector method of mootools is used, if an inappropriate selector is used, for example

$ ('[ATTR = 123]');

An error is reported. Why?

Check the mootools source code and find that his selector simply uses the following logic when traversing all nodes:

 

 

 
Getproperty: function (attribute) {var key = attributes [attribute]; VaR value = (key )? This [Key]: This. getattribute (attribute, 2); Return (bools [attribute])? !! Value: (key )? Value: Value | NULL ;}

 

 

The problem lies in this. getattribute (attribute,2) Parameter 2.

 

 

Because I use documentelement as the userdata carrier node

Document.doc umentelement. addbehavior ("# default # userdata ");

After the statement is executed, ie will overwrite the getattribute method of the node. this new re-write method. only one parameter is supported. this method is implemented in C ++. dynamic parameters are not supported. if you pass the second parameter, an exception will occur.

 

When this indicates document.doc umentelement is an HTML node, it is obvious thatCodeThe overwritten method is executed, and the second parameter is passed in.

 

Okay. Here you may ask me. Why do you have to use documentelement as a carrier? Isn't it OK to select another node? Unfortunately, when the selector method above is called, we need to traverse all the nodes... Which node can I use to escape this curse ?. (If this node is not on the DOM tree, addbehavior will report no permission .).

 

So who is the fault of this tragedy? I don't think I was the one who wrote $ ('[ATTR = 123]'); or who used userdata. it is the evil Microsoft. since you have designed the second parameter for the original getattribute method of your node .. so you, When you rewrite him. why is the second parameter removed? Even worse, you still don't give him fault tolerance.

Okay. Now it's okay. Either I want someone to stop using mootools or I don't need userdata. Either I use a complicated solution to modify the operation method of userdata, or someone else needs to modify the source code of mootools or selector.

 

Let's talk about some other things. jquery has taken this issue into consideration.

People have made a decision to dynamically switch and choose to use parameter 2 or not.

 

Finally, add the getattribute method. The second parameter value is 2.

 

For a tag a, when we use the getattribute method to obtain its href attribute, the second parameter plays a key role:

See the following table:

Obtain the differences between the href and SRC attributes in the browser (relative address and automatic encoding)
  . Href Getattribute ("href ") Getattribute ("href", 2)
IE6 Relative to absolute, not encoded Relative to absolute, not encoded Original Value
IE7 Relative to absolute, Chinese characters are not encoded, and special characters are encoded. Relative to absolute, Chinese characters are not encoded, and special characters are encoded. Original Value
IE8 as IE7 Relative to absolute, Chinese characters are not encoded, and special characters are encoded. Relative to absolute, Chinese characters are not encoded, and special characters are encoded. Original Value
IE8 Standard Relative to absolute, Chinese characters are not encoded, and special characters are encoded. Original Value Original Value
Firefox 3.0 + Relative to absolute, all encoded Original Value Original Value
Google Chrome 2.0 + Relative to absolute, all encoded Original Value Original Value
Safari 4.0 + Relative to absolute, Chinese character encoding, not special characters Original Value Original Value
Opera 9.6 + Relative to absolute, Chinese character encoding, not special characters Original Value Original Value

 

Supplement:

1. ie9, it seems that only getattribute ('href ', 4) can be converted to absolute. The encoding behavior is: Chinese character encoding, =? And so on.

2. according to the test of tomato, if it is in IFRAME, IE browser is a bit incredible. You Need To appendchild the created a element to the document of IFRAME before obtaining the absolute path based on the iframe url, the obtaining method is the same as that in section 1.1. Other browsers do not have this problem and do not use appendchild.

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.