开发者

to return the value of iframe inside the body using jquery

I'm using the wysihat-engine on my jsp. It works well, but when I tried to add a preview feature that is suppose to read from the on-fly created iFrame and put it's value inside the hidden preview div, it couldn't read the iframe's included html. Any work-around for this? Thanks! In this example i want to return the value inside the body using jquery

the following iFrame is not written inside my jsp, but it is attached to a div by WYSihat.js file:

<iframe id="iframeId" class="abc">
   <html>
      <head></head>
      <body>开发者_如何学JAVA;
        <br>
        some text here 
        </br>
    </body>
  </html>
</iframe>

How to return "some text here" and pass it to the following function: Hint, this iFrame has been created on fly by the WYSiHat.js file, as it is not hard written inside my jsp page

function preview() {
    alert("hi"+$('iframe.editor').contents().find('body').text());
}


Your description is certainly confusing, however to access the contents of an iframe you must use the contents() method on a jQuery object:

$('iframe.abc').contents().find('body').text();

Here we have selected the iframe itself, then got its contents. From there we can search the iframe's DOM normally using find().

For more information on the contents method see the jQuery docs.


To find an element inside an iframe, you can use the jQuery function .contents(), which returns the document object of the iframe:

$('iframe.abc').contents().find('body').html();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜