| View previous topic :: View next topic |
| Author |
Message |
Eternal Darkness

Joined: 24 Feb 2007 Posts: 4
|
Posted: Sat Feb 24, 2007 7:14 am |
|
|
|
| ariel wrote: |
I'm just going to assume at this point that it can't be done.
For anyone else reading this:
No, you cannot make a link target an iframe on a seperate page from the one the link is on.
A link on page1.html cannot open page2.html and "load" that link into a frame or iframe on page2.html. |
That's my problem too ^. I just forgot how it can be done, but it CAN be done, I repeat, it CAN be done. I'll ask my teacher on HTML how to do it... I just forgot it... |
|
SteveH
Joined: 11 Apr 2007 Posts: 208
|
Posted: Wed Apr 11, 2007 1:47 pm |
|
|
|
Can't be done with HTML alone, but here's a JavaScript solution.
Use a delimiter in your link such as a question mark. Don't worry, the browser will load the URL correctly even with the delimiter. Like so:
| Code: |
| <a href="page_with_iframe.htm?page_to_load_into_iFrame.htm"> |
On your page with the iFrame, use a JavaScript to parse the part of the URL after the delimiter like this:
| Code: |
<script type="text/javascript" language="javascript">
function loadIF() {
iFrameSrc=location.href.split('?');
if ( iFrameSrc[1] != null ) {
document.getElementById('iFrameName').src=iFrameSrc[1];
}
else {
document.getElementById('iFrameName').src='default_page.htm'
}
}
</script>
|
In this example, you want the script in the head of the document, and your function call in the opening <body> tag:
| Code: |
| <body onload="loadIF()"> |
You can run the script without the function wrapper and <body onload="loadIF()"> function call as long as the script appears after the iFrame code -- the iFrame must be created on the page before the script can find it.
Cheers, hackers. |
|
patsol
Joined: 14 Apr 2007 Posts: 1
|
Posted: Sat Apr 14, 2007 8:50 am |
|
|
|
Steve,
I ran across your solution for a very similar problem I was having ..thank you for posting it.
It's working great in my setup (only difference is the originating link comes from w/in a different iframe on the separate page) except for one thing...
Here's the setup:
Page1.php (starting page with Iframe)
Page1_a.php (Iframe w/in Page1.php)
Page2.php (destination page with Iframe)
Page2_a.php (Iframe w/in Page2.php)
Link in Page1_a.php:
| Code: |
| <a href="Page2.php?TargetPage.php?date=20070407" target="_parent"> |
The end result is Page2.php successfully loads and within its Iframe, "TargetPage.php" gets inserted. The problem is the variable "?date=20070407" does not. My guess is it has to do something with the delimiter used in the JS code, but I can't figure it out (tried using other delimters, but it loads a 404 page).
Any help would be greatly appreciated.  |
|
Keikura

Joined: 24 Mar 2007 Posts: 167 Location: U.K.
|
Posted: Sat Apr 14, 2007 9:46 am |
|
|
|
For multiple URL variables the format is...
| Code: |
| http://www.yourwebsite.com/index.php?page=news&item=12 |
This works for PHP when you use $_GET['...']. |
|
SteveH
Joined: 11 Apr 2007 Posts: 208
|
Posted: Sat Apr 14, 2007 2:09 pm |
|
|
|
Clarification on the JS: Where I have "getElementById('iFrameName')", that should be "getElementById('iFrameId')". FireFox requires the iframe to be identified by the id='' attribute when calling getElementById. Go figure
Hi, Patsol.
I'm not sure where you want the date to go, so I'm going to make a guess as to the right direction.
When you split('?') with two '?' delimiters, you get three array objects.
With "<a href='Page2.php?TargetPage.php?date=20070407'>" the array objects are:
yourArray[0] is "http://www.yoursite.com/Page2.php"
yourArray[1] is "TargetPage.php"
yourArray[2] is "date=20070407"
To split the date into an array:
| Code: |
| theDate = yourArray[2].split('='); |
That gives you two array objects:
theDate[0] is "date"
theDate[1] is "20070407"
If you need Page2_a.php to grab the URL from within the iframe on Page2.php, then you can refer the script to the parent object:
| Code: |
...
iFrameSrc=parent.location.href.split('?');
...
|
Are we close?
~Steve |
|
Keikura

Joined: 24 Mar 2007 Posts: 167 Location: U.K.
|
Posted: Sat Apr 14, 2007 2:22 pm |
|
|
|
| SteveH wrote: |
Clarification on the JS: Where I have "getElementById('iFrameName')", that should be "getElementById('iFrameId')". FireFox requires the iframe to be identified by the id='' attribute when calling getElementById. Go figure  |
All browsers require the id attribute to be set if your gonna use getElementById().
edit: I know we're using JavaScript here but, doesn't anyone have access to PHP?
I mean this would make all this incredibly easy - passing variables between pages via the URL using $_GET['...'] or sessions using $_SESSION['...'] and then loading the correct iframe page. All of which would still be modifiable by JavaScript. |
|
SteveH
Joined: 11 Apr 2007 Posts: 208
|
Posted: Sat Apr 14, 2007 9:00 pm |
|
|
|
Hi, Keikura.
I'm in absolute agreement that id='' SHOULD be used when using getElemementById(), and that is the standards-based method which I expect will be required as browsers become more strictly standards compliant. Currently, though, both IE6 and Opera9 work with just the name='' attribute (I've only tested in FF2, IE6 and Op9).
A PHP method would look like this:
Assuming you are trying to pass the 'date=' value to the Page2.php iframe, replace the ampersand before 'date' with a question mark in the link on Page1_a.php:
| Code: |
| <a href="Page2.php?loadPage=Page2_a.php?date=20070407" target="_parent"> |
That makes the URL of Page2_a.php (loaded into the iframe on Page2.php) "Page2_a.php?date=20070407", thereby retaining the 'date='. You could add more variable=value pairs after 'date=' using ampersands as delimiters such as:
| Code: |
| <a href="Page2.php?loadPage=Page2_a.php?date=20070407&id=304&movie=largeOne.wmv" target="_parent"> |
On Page2.php, your iframe code then becomes:
| Code: |
| <iframe id="iFrameId" src="<?= $_GET['loadPage'] ?>"></iframe> |
Now, again, I don't know what you're doing with the 'date=', and I'm just guessing you want to retrieve the 'date=' value on Page2_a.php inside the iframe. So, just to test to make sure you're getting that variable passed to Page2_a.php, you can write this into the body of document:
| Code: |
| <?php echo('Date = '.$_GET['date']) ?> |
How deep does this rabbit hole go?
~Steve |
|
cedric
Joined: 22 May 2007 Posts: 1
|
Posted: Tue May 22, 2007 5:10 pm Found the php code for ya - just did it myself |
|
|
|
Now, keep in mind - you must have:
A) php enabled on your server, and
B) your main page must be named with the .php extention (and subsequently you may want your documentroot to have index.php in it, or whatever)
| Code: |
<!--iframe start-->
<?php
if (!isset($_GET['target'])) {$target = "this_is_the_name_of_the_default_iframe_source.html"; }
else {$target = $_GET['target'];
}
?>
<td width="79%" align="center" align="middle">
<center>
<iframe src="<?php print $target; ?>" allowtransparency="true" name="Content" scrolling="auto" frameborder="0" height="760" width="100%">
</iframe>
</center>
</td>
<!--iframe end--> |
You should now be able to link: http://www.mysite.com?target=mytarget.html (or "mytargetfolder" can work too, if you have a folder structure set up with, say, index.html as your default folder)
You can see examples here:
Main Page: (defaulted to home.html)
http://www.behemoth.ca
or Cities & Scenery Gallery:
http://www.behemoth.ca?target=cities_scenery/index.html
or People & Objects Gallery:
http://www.behemoth.ca?target=people_objects |
|
xoxo
Joined: 27 May 2008 Posts: 1
|
Posted: Tue May 27, 2008 2:09 pm Hidden Form Fields |
|
|
|
Hello everybody!
I was searching a solution like the one has been given here, I'm very grateful.
I would like to know if it is possible to pass hidden form variables from the first form, to the page that appears in the iframe of the second page.
Is that possible?
Thank you very much. Your help is really appreciated in advance.
Best regards. |
|
Titans98
Joined: 21 Sep 2008 Posts: 1
|
Posted: Sun Sep 21, 2008 5:26 pm how can it work with an html page |
|
|
|
Hi Thanks for JavaScript.
It works well as long as your Iframe link is not a php url including an'?'in it.
Setup:
Page1.html with Link
Page2.html with the javascript and Iframe
My link:
| Code: |
| <a href="page2.html?http://www.otherpage/blog/index.php/news?blog=2"> |
How can this work into an html page instead of php page shown before? Can we replace a PHP question mark by something else that does not confuse the js?
I am starting out obviously and would greatly appreciate your help. |
|
jacturne
Joined: 21 Nov 2008 Posts: 2
|
Posted: Fri Nov 21, 2008 1:49 pm |
|
|
|
| ariel wrote: |
I'm having this same problem.
Here's what I want to do: Have an external link on a non-framed page link to either an iframe or a frame inside a seperate frameset.
These will not be relative links, they'll be fully qualified http://www.etcetc URLs.
The upshot will be external links loaded with my own small nav bar at the top, but it doesn't have to be a frameset. |
Might be years late but I found a solution for you.
http://www.programmingtalk.com/showthread.php?t=31814 |
|
|