...

View Full Version : linking to an iframe in another page



newfoundnoise82
04-29-2006, 01:47 AM
i have been looking all over the web and i can't get to where i need to be to finish my page. basically i have two pages and if someone clicks a specific link from the first page i want it go to the other page but load a specific page in the iframe on the second page.

i know how to use javascript to make a specific page load into an iframe but not how to make the page load into the iframe on another page. all i need to know is how to do it for one page then i think i can build the decision structure around it to make it work for more than one link (hopefully).

any help will be greatly appreciated. thanks.

gmn17
04-29-2006, 02:57 AM
<html>
<head>
<title>iFrames</title>
</head>
<body bgcolor="#cccccc">
<p>
<a href="page1.html" target="contentFrame">page 1</a> |
<a href="page2.html" target="contentFrame">page 2</a> |
<a href="page3.html" target="contentFrame">page 3</a> |
<a href="page4.html" target="contentFrame">page 4</a>
</p>
<iframe name="contentFrame" src="page1.html" width="500px" height="300px" scrolling="auto" frameborder="0"> Warning: Your browser does not support iframes.</iframe>
</body>
</html>

newfoundnoise82
04-29-2006, 05:26 AM
i already knew how to do that. what i need to know is how to click a link on the first page that would then open up a new link and open up the appropriate page in the iframe according to what value was passed to the new page.

i figure it requires passing a value but i have no idea how to do this in javascript.

Kor
04-29-2006, 08:23 AM
I don't know exactly what you intend to do, but you might give your iframe and id as well, say id="contentFrame". Now you may reach the iframe loaded page's document as:

document.getElementById('contentFrame').contentWindow.document

newfoundnoise82
04-29-2006, 08:41 AM
ill rephrase my prob since i guess i didnt do a good job of explaining things before.

let's say i have two pages, page A is just a regular web page. page B though is a regular web page with an iframe in it.

what i want to happen is when a link on Page A is clicked, page B will load but it will also load up a specific page in the iframe, the page to load in the frame will be determined by the value passed to it from the link on page A.

Kor
04-29-2006, 08:55 AM
You may pass a parameter via address bar, same as a querry

newfoundnoise82
04-29-2006, 09:00 AM
please if you can dumb down how exactly to handle this. i have messed with javascript a very minimal amount.

Pim_is_my_name
06-05-2006, 02:02 PM
Hi newfoundnoise82,

i think I know what your problem is because i'm having the same myself. I found a solution but it is in PHP. So maby somebody can translate it to JavaScript?

Here is it:

==========================================================

Have the index page pass a simple variable in the query string, then have the page with `nav & iframe` use that variable to determine what to put in the iframe's contents by default.

Using PHP as an example:
If your navigation contents are "Work - About Us - Something else", the links could be "nav.php?action=work", "nav.php?action=about_us", "nav.php?action=something"

I would then put the following block of code at the very top of the page

PHP Code:
switch($_GET['action']) {
case 'work': $src='work.html'; break;
case 'about_us': $src='about.html'; break;
case 'something': $src='else.html'; break;
default: $src='default.html'; break;
}



And when you declare your iframe, do it as follows:
<iframe src ="<?=$src;?>"></iframe>

==========================================================

Let's hope someone can help us!!

Mr J
06-05-2006, 05:10 PM
Please try the following

Your links in page A would be


<a href="pageb.htm?iframepage1.htm">Iframe page 1</a><br>
<a href="pageb.htm?iframepage2.htm">Iframe page 2</a><br>

In page B


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">
<!--

function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))

window.frames["myiframe"].location=url
}
}

onload=loadIframe
//-->
</script>


</HEAD>
<BODY>


<iframe name="myiframe" id="myiframe" src=""></iframe>

</BODY>
</HTML>

Pim_is_my_name
06-06-2006, 06:52 PM
yessssssss!! :D

tnx Mr. J

it works great!!! And just when I was giving up the hope!!
so thanks again!! :thumbsup:

Pim_is_my_name
06-06-2006, 07:55 PM
humzzzzzzz.....:confused:
only now the url in the location-bar stays the same as the first press't button.
check the site: http://home.planet.nl/~lind2304/deschans/

And i'm working on a script that will also change the button when it's on the page. It's not working correctly with the 'loadIframe' function. :(

Mr J
06-06-2006, 10:08 PM
Just slightly puzzled here,

You have implimented the script and the links in the first page but in all your other pages you have only put in the script and not changed the links therefore in these pages the script is non functional.

Also the links in your other pages all use the target attribute to load the iframe?

Pim_is_my_name
06-06-2006, 10:30 PM
well i'm not sure what you mean. I did it exactly the way you told me to. It did look like a very simple sollution to me then. But with the things you're saying now, you make it seem harder then i thought it was.

What can I do to solve the problem? Maby some script for the location-bar? And a (when opening iframe1, open image1) javascript for the navigation.

(Sorry i don't know much about JavaScript):o

Mr J
06-07-2006, 02:00 PM
It's probably me getting confused.

The location bar will only show the url of the parent page as far as I know

Pim_is_my_name
06-07-2006, 05:01 PM
well it's not a big problem. But it's still something that should de fixed. I'm gonna look for something that will get the button to change to te right image.
Thanks for your help anyway!! The most urgent thing is fixed, so that's a start!!

Mr J
06-07-2006, 11:00 PM
The examples here may help you with your buttons

www.huntingground.freeserve.co.uk/imagery/img_links.htm

Pim_is_my_name
06-08-2006, 05:31 PM
yeah, but that's not working if you use iframes!!

Mr J
06-08-2006, 07:23 PM
Try the example, open page a first

levroi
03-21-2010, 10:43 PM
Hi,

it seems mr J's help worked out for some. But if anyone could help some more I would be very thankfull...
I have exactly the same question. I need to be able to load a page in an iframe on another page as the page from where you click on the link. So a another page has to be opened and on this page there is an iframe in which my link must open.

I have copied the code from mr J and tried several things with it, but I don't understand it. I made 2 pages, called pageA.htm and pageB.htm, just like the example.

pageA.htm:
<a href="pageb.htm?iframepage1.htm">Iframe page 1</a><br>
<a href="pageb.htm?iframepage2.htm">Iframe page 2</a><br>

PageB.htm:
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">
<!--
function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))
window.frames["myiframe"].location=url
}
}
onload=loadIframe
//-->
</script>
</HEAD>
<BODY>
<iframe name="myiframe" id="myiframe" src=""></iframe>
</BODY>
</HTML>


When I click on the link in pageA.htm pageB.htm is indeed loaded with an iframe in it. But what is loaded in the iframe???? I can't figure it out.

What does "iframepage1.htm" in the link "<a href="pageb.htm?iframepage1.htm">Iframe page 1</a><br>" mean? This is written in the code from pageA.htm. Does this mean that a page1.htm will be loaded in the iframe? I have made a new page called page1.htm in which I wrote "hello". But it doesn't show after clicking on the link in pageA.htm, although pageB.htm does open with an iframe as mentioned.

How can I point out to a specific htm file within this link construction?

Hopefully anyone has the answer. Thanks a lot, greetz Levroi!

Mr J
03-22-2010, 09:20 AM
Did you change iframepage1.htm to the name of your page loading into the iframe?

yourpage.htm

Philip M
03-22-2010, 09:35 AM
Example:-

<a href="pageb.html?http://www.google.com">Iframe page 1</a><br>
<a href="pageb.html?http://www.javascriptkit.com">Iframe page 2</a><br>

raghav_vs
04-13-2010, 04:25 AM
Thanks Mr. J for the cool solution... ;)

I don't know if it makes any difference, but, my implementation worked with the onload="loadIframe()" included in the <body> tag...

Anyway... thanks a lot!! :)

jean1907
06-09-2010, 07:08 PM
Is there some way to modify this so that I can put in a "default" path for the iframe so it does not sit empty?

*I've tried a putting in a src path in the iframe itself - but what happens is it loads the src and then reloads the clicked on string from the other page. (so it's loading twice and that doesn't look so good). Would it be an "Else" command?


function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))

window.frames["myiframe"].location=url
}
}

onload=loadIframe

FBGR
11-10-2010, 11:21 AM
Did you change iframepage1.htm to the name of your page loading into the iframe?

yourpage.htm

Please explain in a way that I understand (Im not stupid but not far from)
How do I change size on a selected table in iframe, Im trying to embed a map 730x350 pxl, all I get is the default frame showing the left corner of the map.

KikoaManu
01-31-2011, 08:31 PM
I used this script and worked well, but I realized that anyone can control the content of my iframe. Someone could post a link anywhere with "mypage.html?maliciouscontent.html" and people might think the content is mine or they could fill in a form thinking they are sending it to me.

Does anyone know how to limit the script so that it will only open the links I want?

Thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum