# Dynamic text highlighting

**URL:** <https://www.ruby-forum.com/t/dynamic-text-highlighting/93160>\
**Category:** Rails\
**Created:** [April 28, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/dynamic-text-highlighting/93160 "2007-04-28T14:51:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomas](https://www.ruby-forum.com/u/tomas)\
**Post date:** [April 28, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/dynamic-text-highlighting/93160/1 "2007-04-28T14:51:51Z")

</div>

Hi,

consider following situation:

I want to load an external site A.html in an iframe. As far, no problem.

But now, I want to load it with words hightlighted on it, like Google’s  
cache result pages. Unfortunately, the decision, which words should  
highlighted is done on run time.

Is it possible to replace the original content with my content on the  
fly?

Thanks.

Best regards,  
Tomas

---

<div class="post-metadata">

**Author:** ![tomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomas](https://www.ruby-forum.com/u/tomas)\
**Post date:** [May 1, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/dynamic-text-highlighting/93160/2 "2007-05-01T14:54:00Z")

</div>

On 28 Apr 2007, at 13:51, Tomas F. wrote:

> I want to load an external site A.html in an iframe. As far, no  
> problem.
> 
> But now, I want to load it with words hightlighted on it, like  
> Google’s  
> cache result pages. Unfortunately, the decision, which words should  
> highlighted is done on run time.
> 
> Is it possible to replace the original content with my content on the  
> fly?

Yes, you can do that if you route the request/response through your  
Rails app.

E.g. in your index action, make a Net::HTTP request to your external  
site, gsub the response’s body to your heart’s content, then send the  
end result to the browser.

If you want the user to be able to navigate around the external site,  
you’ll have to rewrite all the hyperlinks so that they point back to  
your own action, with the real path stored in a param somewhere, so  
your action can make another HTTP request to the appropriate part of  
the external site, gsub the response’s body (including hyperlinks)  
and send the result to the browser.

Regards,  
Andy S.
