Forum Moderators: open
Link looks like this:
<a href="page1.htm?doo.htm">page2: loads doo.htm</a>
On page2.htm:
When page has loaded, or at least after the IFRAME's HTML has loaded,
get the query string..
var query = location.search.substring(1) // removes the "?"
document.frames["_iframe_id_"].src = query
can you change this script and send it back?
thx a ton if you can..
"Page 1"
[google.com...]
"Page 2"
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
var urltext = document.location.href;
if (urltext.indexOf('?')!= -1)
targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else
targeturl = document.location.href;
// defaults to current page if no parameter is passed
function init(){
document.forms[0].p_requested_url.value = targeturl;
}
//-->
</script>
</head>
<body onload="init()">
<form>
<input type="hidden" name="p_requested_url" value="">
</form>
</body>
</html>
Page be is loading, but then the entire page changes to the html file that should load in the iframe.
I changed
function init(){
document.forms[0].p_requested_url.value = targeturl;
}
to
function init(){
location.replace(targeturl);
}
where do I specify the iframe name "content"
thx!
Step 1: Click a link on page a
<a href = "../somedir/pageb.html?iframepage.html">Click here</a>
Step 2: Go to page b which contains the iframe
[browser takes you to pageb.html]
Step 3: Change the iframe's content to the substring
So, now, the browser is loading page b. On page b, you put that code that you have which strips out the substring information (everything after the? in the url).
<script language="JavaScript" type="text/javascript">
<!--
var urltext = document.location.href;
if (urltext.indexOf('?')!= -1)
targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length); //this gets the substring i.e. - the name of the iframe
else
targeturl = document.location.href;
// defaults to current page if no parameter is passed
function init(){
document.framename.src = targeturl;
}
[pre]
window.onload = init
//! change ¦¦ to unbroken pipes (ctrl+\)
function init()
{
var query = location.search.substring(1) // removes the "?"
// if query is empty string, default.htm is used
document.frames["_iframe_id_"].src = query ¦¦ default.htm
}
[/pre] You want the iframe to default to the current page?
*page one link:
<a href="infection.html?infect_prevent/occupation_overview.html" target="_self">Occupational
Exposure to Bloodborne Pathogens</a>
*page two with an iframe:
//the javascript
var urltext = document.location.href;
if (urltext.indexOf('?')!= -1)
targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else
targeturl = document.location.href;
// defaults to current page if no parameter is passed
function init(){
document.content.src = targeturl;
}
* in the body tag
<body onLoad= "init()" >
*iframe name "content"
It is loading page2, but Im just getting the default iframe content.
If that doesn't work, try the following
var urltext = document.location.href;
alert(urltext.indexOf("?"));
if (urltext.indexOf('?')!= -1)
targeturl = urltext.substring((urltext.indexOf('?')+1),urltext.length);
else
targeturl = document.location.href;
// defaults to current page if no parameter is passed
All I'm doing here is adding an alert to see which fork of the if statement the script is taking.
If that works, remove the alert and you're good to go.
index.html
<html>
<body>
<a href=infection.html?ifsrc=infect_prevent/occupation_overview.html>go to intro</a>
</body>
</html>
infection.html
<html>
<script>
function getSource()
{
ifsrc=location.search.substring(1)
ifsrc=ifsrc.substring(6,ifsrc.length)
alert(ifsrc)
document.getElementById('content').src = ifsrc
}
</script>
<body onLoad="getSource()">
<iframe id="body" name="content" width="400" height="430" scrolling="yes" frameborder="0" marginwidth="0" marginheight="0" ></iframe>
</body>
</html>
this also had problems. when I clicked on infection.html link from the index.html(the default iframe) I would get a blank frame.