4549

Jquery - Jquery Wysiwyg return html as a string

I am using the Jquery Wysiwyg editor and I am trying to capture the html that makes up the content area to store in a DB. Is there anyway to get html of a element and save it as a string? My code looks like tihs

<iframe id="wysiwyg_IFrame"> <html> <head></head> <body> <ul> <li>This is a test</li> </ul> </body> </html> </iframe>

I would either like to get a string that starts with <html>....</html> or just the body <body>...</body> does anyone know if this is possible? Thanks

Answer1:

I figured out the answer and it was within the horrible documentation of the Jquery Wysiwyg. It actually wasnt even in the documentation it was in part of the wiki. To get the contents you just need to use the text areas divs name and the .va() so for me it was

$('#wysiwyg').val();

If you want to set the contents like I am trying to d, ex. grab something from the DB and place it in the text area of the jquery wysiwyg when a page loads, you need to use the setContent method and it would look like this

var content = 'place me in the text area'; $('#wysiwyg').wysiwyg('setContent', content);

Thanks for all the answers and yes .html() seems to work in all other instances but will not work with the jquery wysiwyg.

Answer2:

You can get the HTML of an element via the jQuery html function:

var htmlString = $('#wysiwyg_IFrame').html();

Alternately, just use the DOMElement's own innerHTML property, it's now part of the HTML5 standard and it's been supported in all major browsers (including IE — in fact, it was a Microsoft innovation) for years:

var htmlString = $('#wysiwyg_IFrame')[0].innerHTML;

Answer3:

That should works:

var html = $("#wysiwyg_IFrame body").html();

Answer4:

var theHTML = $('#wysiwyg_IFrame').html();

Answer5:

$('wysiwyg_IFrame').content().find("body").html()

returns everything between the body tags of the html file loaded in your iFrame

Answer6:

$('#wysiwyg_IFrame').html() does not work?

<strong>Update:</strong>

Try .contents():

$('#wysiwyg_IFrame').contents().find('body').html()

or

$('#wysiwyg_IFrame').contents().html()

From the docs:

The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.

Recommend

  • Why prefer var strList = new List(); over List strList = new List();? [closed]
  • MFP CLI 7.1 adapter wont deploy with mfp push command
  • Jquery sending key/value paired array to PHP
  • Why is bash so painfully slow in boot2docker for Windows?
  • Shake iPhone to open my app. Possible?
  • ZF2 Event before not_found_template
  • Animating an SVG Group
  • Easy way to convert a Bitmap and Png Image to text and vice versa
  • ng-repeat not working with table but works with list
  • Function JavaScript : on Menu CSS HTML
  • Can't delete li from to-do list
  • OpenGL - Object Transformations and VBOs
  • Cut the background to expose the layer below
  • How to disable all widgets inside Panel or inside Composite?
  • converting text file into xml using php?
  • Tamper-proof configuration files in .NET?
  • SharedPreferences or SQLite Database?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Python urlparse: small issue
  • Python CGI os.system causing malformed header
  • Using jQuery closest() method with class selector
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Nant, Vault & Windows Integrated Authentication
  • What is Eclipse's Declaration View used for?
  • swift auto completion not working in Xcode6-Beta
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Java applet as stand-alone Windows application?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • JSON with duplicate key names losing information when parsed
  • SVN: Merging two branches together
  • Confusion with PayPal's monthly billing cycle
  • Arrays break string types in Julia
  • SQL merge duplicate rows and join values that are different
  • WPF Applying a trigger on binding failure
  • Java static initializers and reflection
  • Append folder name and increment by 1 using batch script
  • Reading document lines to the user (python)
  • Observable and ngFor in Angular 2