View Full Version : loading a link on demand from another page (Iframe SSI 2)

03-19-2011, 09:26 PM
1) Script Title: Iframe SSI 2

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm

3) Describe problem: This isnt a problem as such - I was just wondering if a page can be loaded into the iframe from a link that is on another page (of the same site) ?

03-20-2011, 01:25 AM
If you're using PHP or another server side language you could just put it in the GET or other data for the top page. I think you know how that works, you pass the page name or a token that resolves to the page name and have the src attribute of the iframe written by the server.

If no server side language is available, a javascript 'GET' can be used. The principle is the same only everything is done on the client side. If you need this, here's a simple javascript function to read a GET type query string:

function getQval(n) {
if(typeof n !== 'string'){
return null;
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;

So if your link on the other page is href="index.htm?ipage=aboutus", on index.htm you could do like:

if (getQval('ipage') === 'aboutus'){
//do something here to make the src attribute of the iframe be "aboutus.htm"

In any case, as I think you know, the top page and the page in the iframe must be on the same domain. Your question implies that you don't know that the other page:

I was just wondering if a page can be loaded into the iframe from a link that is on another page

That other page, as long as it isn't the top page or the page in the iframe, it doesn't have to be on the same domain.

03-20-2011, 01:48 AM
Thanks for that John - I'll have a better look at it in the morning but its close to 2am here and my brain is flagging.

- All the pages are on the same domain BTW :) -

03-20-2011, 02:04 AM
I should note that doing this is sketchy. The iframe script doesn't support Opera. Depending upon the layout of the included page, there may be problems getting the iframe to resize properly in some or all of the browsers the script does support. You might be better off with a real server side include or AJAX. That's not to say those methods don't also have their drawbacks, I just feel more comfortable ironing those out than working with the iframe script, which hasn't ever been fully worked out in my opinion, and perhaps never really can be.