Welcome to WebmasterWorld Guest from 54.226.25.231

Forum Moderators: open

Message Too Old, No Replies

Copy HTML to JavaScript variable WITHOUT using innerHTML?

     

JAB Creations

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

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



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

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

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



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

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

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



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

JAB Creations

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

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



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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month