Safari Source Code

Is anyone familiar with Native Code in Safari OS X (version 3 and WebKit)? I use Javascript to parse some information on the form, and one of my inputs is called "tags." When trying to get the value of this element with:

// button is being passed through a function as a DOM object var tags = button.form.elements["tags"].value; 

Safari returns some kind of function. I got it to warn values ​​like "function tags () {[native code]}" and Node Trees, but I just don't understand why I will have problems. If anyone has a key, please let me know. I started by changing the input name to something else, as well as iterating through all the elements and using the if () operators to determine if this is the element I want, but I'm terribly interested to know why Apple restrict the use of any element forms with the name "tags" ...

PS - It checks and works fine in firefox.

+2
source share
1 answer

[native code] means that it is a function built into the browser, not written in JavaScript. tags is a WebKit extension for the DOM so you can get a list of elements in the form by tag name. For example, if I run this on the StackOverflow page, I get the response text area:

 document.getElementById('submit-button').form.elements.tags("textarea")[0] 

The problem is that the index in the collection in JavaScript also has access to any properties of the object (including methods), so when you try to access the named element tags , instead you get a method on the elements object that WebKit defines. Fortunately, there is a workaround; you can call namedItem on the list of elements to get the id or name element:

 var tags = button.form.elements.namedItem("tags").value; 

to change . Note that it is probably best to use namedItem in general even in other browsers if you need to get an element named item or length or something like that; otherwise, if you use them as an index with the [] operator, you will get the built-in method item or length instead of your element.

+6
source

Source: https://habr.com/ru/post/1432531/


All Articles