innerhtml

DOM Exception when assigning HTML entities to innerHTML

﹥>﹥吖頭↗ 提交于 2019-11-30 15:13:08
问题 On this page http://blog.zacharyvoase.com/2010/11/11/sockets-and-nodes-i/, running the following code in javascript console will throw an Exception. var div = document.createElement('div'); div.innerHTML = "»"; Chrome 8.0.552.28 Mac: Error: INVALID_STATE_ERR: DOM Exception 11 Firebug in Firefox 3.6.12 Mac: NS_ERROR_DOM_SYNTAX_ERR An invalid or illegal string was specified Safari 5.0.2 Mac: Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7 Opera: works fine But it works fine in all other

get opening tag including attributes - outerHTML without innerHTML

浪子不回头ぞ 提交于 2019-11-30 14:47:50
问题 I would like to retrieve a certain tag element with its attributes from the DOM. For example, from <a href="#" class="class"> link text </a> I want to get <a href="#" class="class"> , optionally with a closing </a> , either as a string or some other object. In my opinion, this would be similar to retrieving the .outerHTML without the .innerHTML . Finally, I need this to wrap some other elements via jQuery. I tried var elem = $('#some-element').get(0); $('#some-other-element').wrap(elem); but

DOM Exception when assigning HTML entities to innerHTML

痞子三分冷 提交于 2019-11-30 14:00:58
On this page http://blog.zacharyvoase.com/2010/11/11/sockets-and-nodes-i/ , running the following code in javascript console will throw an Exception. var div = document.createElement('div'); div.innerHTML = "»"; Chrome 8.0.552.28 Mac: Error: INVALID_STATE_ERR: DOM Exception 11 Firebug in Firefox 3.6.12 Mac: NS_ERROR_DOM_SYNTAX_ERR An invalid or illegal string was specified Safari 5.0.2 Mac: Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7 Opera: works fine But it works fine in all other pages I tried. My questions are what's special about the page and why does chrome and firefox throw an

XSS prevention and .innerHTML

时光毁灭记忆、已成空白 提交于 2019-11-30 12:16:22
问题 When I allow users to insert data as an argument to the JS innerHTML function like this: element.innerHTML = “User provided variable”; I understood that in order to prevent XSS, I have to HTML encode, and then JS encode the user input because the user could insert something like this: <img src=a onerror='alert();'> Only HTML or only JS encoding would not help because the .innerHTML method as I understood decodes the input before inserting it into the page. With HTML+JS encoding, I noticed

get opening tag including attributes - outerHTML without innerHTML

回眸只為那壹抹淺笑 提交于 2019-11-30 11:34:08
I would like to retrieve a certain tag element with its attributes from the DOM. For example, from <a href="#" class="class"> link text </a> I want to get <a href="#" class="class"> , optionally with a closing </a> , either as a string or some other object. In my opinion, this would be similar to retrieving the .outerHTML without the .innerHTML . Finally, I need this to wrap some other elements via jQuery. I tried var elem = $('#some-element').get(0); $('#some-other-element').wrap(elem); but .get() returns the DOM element including its content. Also var elem = $('#some-element').get(0); $('

Javascript innerhtml of checkbox

折月煮酒 提交于 2019-11-30 09:45:36
问题 Well I have some checkboxes with id='0','1','2','3' etc. So I need to get text of checkboxes. Here is code of checkboxes in PHP. '<input id="'.$i.'"type="checkbox" name="option1" value="a1" onclick="checkYears()">'.$years[$i].'</input> So i need to get $years[$i]-value. I'm using this code. while (bool==false) { if (document.getElementById(i)!=null) { if (document.getElementById(i).checked) { years.push(1); yearsValue.push(document.getElementById(i).innerHTML); document.getElementById(i)

If innerHTML is evil, then what's a better way change the text of a link?

橙三吉。 提交于 2019-11-30 08:41:23
I know innerHTML is supposedly evil, but I think it's the simplest way to change link text. For example: <a id="mylink" href="">click me</a> In JS you can change the text with: document.getElementById("mylink").innerHTML = new_text; And in Prototype/jQuery: $("mylink").innerHTML = new_text; works fine. Otherwise you have to replace all of the child nodes first and then add a text node. Why bother? How about document.getElementById('mylink').firstChild.nodeValue = new_text; This won't suffer from the problems described by PEZ. Regarding Triptych's comment and bobince's reply, here's another

How can I tell when changes to jquery html() have finished?

感情迁移 提交于 2019-11-30 07:04:33
I'm using jQuery to change the HTML of a tag, and the new HTML can be a very long string. $("#divToChange").html(newHTML); I then want to select elements created in the new HTML, but if I put the code immediately following the above line it seems to create a race condition with a long string where the changes that html() is making may not necessarily be finished rendering. In that case, trying to select the new elements won't always work. What I want to know is, is there an event fired or some other way of being notified when changes to html() have finished rendering ? I came across the jQuery

Adding option elements using .innerHTML in IE

谁说我不能喝 提交于 2019-11-30 05:24:27
问题 I have a txt variable that contains my html string that I need to set for a drop down list. The code works fine in all the other browsers except for IE. The basic code is shown below. while loop with some more code document.getElementById('theSelector').innerHTML = txt; where 'theSelector' is the id of my select element for my form So basically IE poops out and doesn't generate my list. I'll post my webpage below if you'd like to look at the source and everything that I'm doing. If you want

How do I get the original innerHTML source without the Javascript generated contents?

痞子三分冷 提交于 2019-11-30 04:41:54
Is it possible to get in some way the original HTML source without the changes made by the processed Javascript? For example, if I do: <div id="test"> <script type="text/javascript">document.write("hello");</script> </div> If I do: alert(document.getElementById('test').innerHTML); it shows: <script type="text/javascript">document.write("hello");</script>hello In simple terms, I would like the alert to show only: <script type="text/javascript">document.write("hello");</script> without the final hello (the result of the processed script). I don't think there's a simple solution to just "grab