Forum Moderators: open
How do I load a different url in an iframe?
scenerio:
A page called "services.htm" have an iframe NAME "content" with the default URL "mango.htm" in it.
problems:
Now I would like to have a link from another page where I would call the services.htm and get the iframe Name "content" to load a different url instead of the default one.
How could I accomplice this?
Thank you for your help.
No, that is not what I intended to do.
I don't wish the service.htm to load into the iframe Name "content" but instead would like the service.htm page which contain the iframe name "content" to change the contents inside the iframe to another htm page which is not the default one named mango.htm.
I hope you can understand what I'm trying to say.
example:
Service.htm contain an iframe name "contents" and inside the iframe(contents) have it's default page mango.htm
when I click on the link which is on another page called home.htm, I would like the service.htm to load and at the same time get the iframe(contents) to change to another page named apple.htm replacing the default page mango.htm
I get you now :)
It's a long bit of code, it could be shorter with ASP.. see later.
Here's a javascript version which works in I.E 6 & Netscape 7 at least:
Services.htm:
<html>
<head>
<title>Service</title>
<script langauge="javaScript">
function getQueryString()
{
//
// QueryString
//
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
{
var foo
foo=QueryString("page")
if (foo=="null")
{
//alert("foo")
document.getElementById('contents').src="mango.htm"
}
else
{
//alert(foo)
document.getElementById('contents').src=foo+".htm"}
}
}
</script>
</head>
<body onLoad="getQueryString()">
Service.htm
<iframe name="contents" src="mango.htm" id="contents"></frame>
</body>
</html>
Home.htm
<a href="services.htm?page=Apple">Load Apple</a>
Whatever you put as the page querystring variable will be loaded as the page, for example if you wanted to load "curry.htm" into the IFRAME the link would be services.htm?page=Curry
With ASP you'd use the same queryString function on the link but in the services.asp page you'd have
<%
Dim getPage
getPage=Request.QueryString("page")
IF getPage="" THEN
getPage="mango"
END IF
%>
<iframe name="contents" src="<%=getPage%>.htm"></iframe>
I hope that helps and is what you were after!
Katy
Please help
There's another problem though, when I try to load or preview the service.htm without parsing the variable "page" it didn't load the default mango.htm in the iframe.
Scenario:
example in flash menu:
geturl("../services/service.htm?page=apple")
this didn't work
example in image link:
<a href="../services/services.htm?page=apple">
and this one works
I'm using the flash menu through out the site and one of the menu items have the link to the services.htm
which I have change the link to the one in first example and it is not working.
The image link is the one which I used in the home page to load the services.htm and get the content of the iframe to load the apple.htm instead of the default mango.htm and it's working fine.
I would like to have the service.htm to load as default or as it is when i used the flash menu.