homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Copy HTML to JavaScript variable WITHOUT using innerHTML?
JAB Creations

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

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);


JAB Creations

 10:55 pm on Jul 9, 2011 (gmt 0)

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);

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


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

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.


JAB Creations

 11:42 pm on Jul 9, 2011 (gmt 0)

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...


- John

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved