[Javascript] loading on frame

Ben Curtis Quixote at LaMancha.org
Fri Oct 12 15:44:35 CDT 2001


> <script LANGUAGE="javascript">
> if (self==parent)
>     { 
>         document.write('<b>THIS IS A FRAME ELEMENT!!</B><br>')
>         document.write('YOU WILL BE TRANSPORTED TO FRAMES RIGHT AWAY')
>         document.write('<META HTTP-EQUIV="refresh" CONTENT="1;
> URL=index.html">')
>     } 
> </script> 
> 
> Ok my problem or rather what I wanted is to be able to load this page
> that the visitor tried opening to be loaded on the main page on the
> frame.... 


What you would want to do then is send the first page's url to the
index.html frameset. The code I would use instead of your code above is:

<scrip>
if (self.name != "main" || self == parent)
    top.location.href = "/index.html?main=" + self.location.href;
</script>

Put that script on your pages that are supposed to be in the "main" frame.
It appends the current url to the query string of the destination url. Then
put this script at the bottom of index.html, after the framesets have been
defined:

<script>
if (self.location.search.indexOf('?main=') == 0)
    self.main.location.href = self.location.search.substring(6);
</script>

This extracts everything after "main=" and uses that as the url for the fram
named "main".

--
+Ben Curtis

"One of the symptoms of an approaching nervous breakdown
is the belief that one's work is terribly important."
- Bertrand Russell (1872-1970)









More information about the Javascript mailing list