Click to See Complete Forum and Search --> : Frames help


Zach Elfers
12-30-2002, 03:47 PM
I have been working on my own script to keep a page in frames. I am calling with script with <body onLoad="checkFrames();">:

function checkFrames() {
if (top.location == self.location) {
self.location.replace("framepage.html");
}
return true;
}

This works great BUT I want it to keep the page that the visitor went to.

If it just replaced the page with the frameset page, suppose there was a frame named main. In frame "main" would be the default page which was in the frameset. I want the page that the visitor was at to generate frames, but then replace frame "main" with the new page.

I tried:

function checkFrames() {
siteBookmark = self.location.href;
if (top.location == self.location) {
self.location.replace("framepage.html");
parent.main.location.replace(siteBookmark);
}
return true;
}

I hope you understand what I am trying to say. Any ideas?

pyro
12-30-2002, 05:08 PM
Here's some script I wrote up for a project I did a while ago. I commented it up, so you know what it's doing.

This goes in the <head> of you page that sets your frames.

<script language=javascript>
<!--Hide
linkURL = "homepage.html" //set the default URL to load if there was no referrer
if (top.location.href) { //to be compatible with IE use top.location.href instead of parent.document.URL
pageURL = top.location.href //set the top.location.href to parentURL
if (pageURL.indexOf('?') != -1) { //Check for the referring page
linkURL = pageURL.substring (pageURL.indexOf('?')+1, pageURL.length) //parse the top.location.href to remove everything before the ?
}
}

document.write('<FRAMESET ROWS="67,*,35" Border=0>')
document.write('<FRAME SCROLLING=NO NORESIZE SRC="top.html" NAME="top">')
document.write('<FRAME NORESIZE SRC="' + linkURL + '" NAME="homepage">') //this is the frame that the content is loaded into
document.write('<FRAME SCROLLING=NO NORESIZE SRC="address.html" NAME="address">')
document.write('<\/FRAMESET>')

//End hide-->
</script>


This goes in the <head> of your frames pages

<script language="javascript" type="text/javascript">
<!-- Hide
if (top.location == self.location) { //if page is not in its frameset
top.location.href = "index.html?homepage.html" //send to index.html with the referring page after the ?
}
//End hide-->
</script>

Zach Elfers
12-30-2002, 05:56 PM
Thanks.

pyro
12-30-2002, 05:57 PM
You bet. Hope it works for you. :D