Welcome to WebmasterWorld Guest from 54.158.253.134

Forum Moderators: open

Message Too Old, No Replies

Copy HTML to JavaScript variable WITHOUT using innerHTML?

     
6:15 pm on Jul 9, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts: 3168
votes: 22


I've created a basic rich text editor though I'm having trouble figuring out how to copy the HTML and store it in a JavaScript variable. I could use innerHTML though I could also let my cat site on my keyboard for an hour and save the changes. Thoughts please? I tried the following (to insert the code in to a textarea) though it outputs the typeof even though I'm not using typeof...

- John

var c = document.getElementById('test').cloneNode(true);
document.getElementById('post').appendChild(c);
10:55 pm on July 9, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts: 3168
votes: 22


Supported in...

- IE9+ (not IE8).

- Safari 3.0/ all versions of Chrome most likely.

- Opera 8.0+ (not 7.5).

- Firefox 1.5+.

I don't have my usual compliment of browsers installed for testing though it looks like it's pretty well supported. This will become part of an advanced feature which won't be available to people with outdated browsers any way.

I don't suppose anyone knows what version of ECMAScript or the DOM this belongs to by chance?

- John

var s = new XMLSerializer();
var str = s.serializeToString(document);
alert(str);

[edited by: JAB_Creations at 11:38 pm (utc) on Jul 9, 2011]

11:38 pm on July 9, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12548
votes: 2


XMLSerializer is mainly useful for applications and extensions based on the Mozilla platform. While it is available for web pages, it's not part of any standard and level of support in other browsers unknown.


[developer.mozilla.org...]
11:42 pm on July 9, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts: 3168
votes: 22


Thanks coopster, that is actually where I found the answer I was looking for. I've been installing older versions of browsers to test how far back it's supported and I'm glad to say far back. There are proprietary methods for IE8 and older here...

[help.dottoro.com...]

- John