Northband
Northband

Reputation: 453

How to load a page in background?

I have a project where we're using an iframe. However, project specs have changed and we can no longer use the iframe. Instead we need to request the html page in the background and display it on page when loaded.

Any ideas on how to do this via Ruby (rails). Thought best to ask for general direction before diving in.

Thanks!

Upvotes: 0

Views: 115

Answers (2)

the Tin Man
the Tin Man

Reputation: 160571

It depends on where you want to have the work occur, on the back-end in your Rails code, or in the user's browser via JavaScript, as @stunaz suggests.

Keeping it in the browser and loading via JavaScript will expose the HTML page's location to the user, which might not be desirable. Loading it from the back-end and including it in the HTML emitted to the browser will hide the source entirely.

If you want to do it on the back-end, the simplest thing is to either load the file from the local drive, if it is local using File.read. If it's on a different machine, you can use Open::URI to pull it in. Either way, you'd then insert it into the HTML in the right spot. How you do that depends on what you are using to generate the outgoing HTML.

Upvotes: 0

storm_buster
storm_buster

Reputation: 7568

load it with ajax, and do a body append

Upvotes: 1

Related Questions