/    Sign up×
Community /Pin to ProfileBookmark

Force iframe to load within main page?

Hello everyone!

I have been trying to figure this out for hours now, but just can’t seem to find any solution. I’m hoping that someone here can point me in the right direction, maybe give me a hint.

I have a main page that contains an iframe tag and links to a forum:

[CODE]<iframe src=”forum/index.php” width=”100%” height=”100%” frameborder=”0″ name=”content”></iframe>[/CODE]

I’m trying to find a way for the iframe content to load within the main page if accessed by itself, directly, i.e. via search engine or direct link. The tricky part is that the link could have the following format:

[CODE]index.php?action=vthread&forum=1&topic=5[/CODE]

and instead of just linking back to index.php, I would like for the entire string to load in the iframe within the main page.

I have read “force to load in frameset” tutorials, but I have not been successful trying to adjust that to my iframe.

Any tip would be appreciated, thank you very much in advance!
Jael

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreJul 27.2003 — Does your server support server-side scripting, because it could be done with ASP/PHP better than it could in JavaScript.

Failing that, it is possible to do it in JavaScript,. and I will post a working example sometime today.
Copy linkTweet thisAlerts:
@JaelauthorJul 27.2003 — Hello cijori!

Thank you for your quick reply!

I do have PHP support, but no ASP support. I'm using PHP all throughout the site anyway, but I'm [i]not[/i] currently calling pages with strings, i.e. index.php?contact, index.php?links. That's just the way the forum is set up. However, I'm willing to change whatever needs to be changed.

Thank you again!

Jael
Copy linkTweet thisAlerts:
@NevermoreJul 27.2003 — A nice easy solution would be to put this code on top of the forum page and always call it as http://www.your-forum?ok=ok

<?php

if(!$_GET['ok'])header("Location: http://www.evernet.co.uk");

if(!isset($_
GET['ok']))header("Location: http://www.evernet.co.uk");

?>
Copy linkTweet thisAlerts:
@JaelauthorJul 27.2003 — Hi cijori,

thank you for your help!

I don't really understand what this does and how to set this up for the rest of the site. The site is built as follows:

www.domain.com/index.php (main page)

www.domain.com/home.php (content iframe)

www.domain.com/forum/index.php (content iframe)

www.domain.com/contact/index.php (content iframe)

www.domain.com/links/index.php (content iframe)

etc. etc.

I probably have a thinking error here, too. I probably need to put the main page in every folder, since the default main page links to home.php already.

If you could explain to me what that php code does, I might be able to figure more out by myself though.

Thank you again!

Jael
Copy linkTweet thisAlerts:
@NevermoreJul 27.2003 — Put the code in the head of the pages you want to be in the iframe, changing the URLs to the URLs of the page to enclose the frame. Then, whenever you make a link to the iframe (e.g. in src=), you need to add ?ok=ok on the end.
Copy linkTweet thisAlerts:
@JaelauthorJul 27.2003 — Ok, so if the ?ok=ok is NOT at the end of the file (which it wouldn't be via direct link access), one will be redirected to the specified page.

It's working, but I'm still having problems with it. Right now, it does what a basic javascript does. If I enter the link without the ?ok=ok, (i.e. www.domain.com/test/index.php) it redirects to the main page. The main page includes the iframe tag:
[CODE]<iframe src="news.php" width="100%" height="100%" frameborder="0" name="content"></iframe>[/CODE]
So instead of my actual location, I see the main page with the news (www.domain.com/index.php).

I could of course make a main template with an iframe tag for every page to be accessed and change the src to the location like:
[CODE]<iframe src="test/index.php" width="100%" height="100%" frameborder="0" name="content"></iframe>[/CODE]
I can do that with a regular javascript, too, though ("if not loaded in frames, redirect to ...")

So, if I would click a direct link: http://www.domain.com/test/index.php?action=vthread&forum=1&topic=5 it would still refer me to http://www.domain.com/test/index.php and lose the forum topic. I suppose there is no way around that?

Thanks so far though, cijori.

Jael
Copy linkTweet thisAlerts:
@NevermoreJul 27.2003 — Ooops, I didn't quite realize what you were doing.

I haven't tested this, so tell me if it doesn't work (it probably wont, im pretty wired)

<?php

$url = $_SERVER['HTTP_HOST'];

$url = $url . $_
SERVER['SCRIPT_NAME'];

if(!$_GET['ok'])header("Location: http://www.evernet.co.uk?uri=".url);

if(!isset($_
GET['ok']))header("Location: http://www.evernet.co.uk?uri=".url);

?>

and where you have the source of the iframe, replace it with this:

<? php if(isset($_GET['uri'])) echo $_GET['uri'] else echo("ur_default_page.htm"); ?>
Copy linkTweet thisAlerts:
@JaelauthorJul 27.2003 — Did all that. It looks fairly logical, but I'm being redirected to the main page. The address bar then shows www.domain.com/?uri=url, and the frame shows a 404 error (I used the full url just in case, and viewed by itself, the index does show the default iframe).

Also, I was getting errors at first. Not knowing much about php I added a semicolon and removed a space:
[CODE]<?php if(isset($_GET['uri'])) echo $_GET['uri'][COLOR=orangered];[/COLOR] else echo("ur_default_page.htm"); ?>[/CODE]
Not sure if that might have "deactivated" something.

And I don't have to have a solution today. I usually solve problems by sleeping on it. (This one is over my head though.)

Thanks! I really appreciate your help!

Jael
Copy linkTweet thisAlerts:
@NevermoreJul 27.2003 — I don't think you should have the forward slash in the URL. I will make a script tomorrow if it isnt done by then.
×

Success!

Help @Jael spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...