开发者

Jquery - Jquery Wysiwyg return html as a string

开发者 https://www.devze.com 2022-12-31 01:40 出处:网络
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 look

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>开发者_Python百科;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


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.


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;


That should works:

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


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


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

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


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

Update:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消