homepage Welcome to WebmasterWorld Guest from 54.211.34.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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

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



 
Msg#: 4337437 posted 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);
document.getElementById('post').appendChild(c);

 

JAB Creations

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



 
Msg#: 4337437 posted 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);
alert(str);

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

coopster

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



 
Msg#: 4337437 posted 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.


https://developer.mozilla.org/en/XMLSerializer

JAB Creations

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



 
Msg#: 4337437 posted 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...

[help.dottoro.com...]

- 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