1

I try to highlight text in a page use jquery.highlight-4.js.

$('body').highlight('t');

My webpage contain an iframe which source on the same domain.

It doesn't work for text inside iframe ( the iframe is on same domain with my web page).

Please help me.

Thelinh Truong
  • 564
  • 1
  • 8
  • 19

3 Answers3

1

$(iframeID).contents().find('body').highlight(keyword);
or
var iframes = document.getElementsByTagName("iframe"); $(iframes[0].contentWindow.document.body).highlight(keyword);

And don't forget to add .highlight { background-color: yellow } to the style of the sub-page in the iframe.

KnIfER
  • 712
  • 7
  • 13
0

think you should get the iframe first, like $("#frameID"), then you can manipulate with something in that...

nhanlc
  • 103
  • 2
  • 8
0

Your code is highlighting the entire body, however the content inside the iFrame is not, by most browsers, considered to be in the same body as the current document.

In short, $('body') includes everything in the page but things inside an iFrame is excluded (due to the awkward nature of iFrame).

Highlight the content by explicitly selecting it using jQuery instead.

I tend to avoid iFrame at all cost. jQuery is pretty powerful in real-time manipulation of HTML contents that I was never really forced to use an iFrame.

Gapton
  • 2,044
  • 2
  • 20
  • 33