Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

frame matching: eternal loop 1

Status
Not open for further replies.

realtree

Technical User
Aug 5, 2003
53
CA
Okay.
I have a page of frames. The 'topguh' frame is a title page changes along with the 'main' frame when a button is clicked on the 'menu' frame. The problem is that sometimes the 'menu' frame doesn't match the 'main' frame and vice versa. So what I did is put in onLoad code that checks for the proper frame, and also makes sure that the page is actually in a frame to begin with. If the page is not in a frame, then init_webs.html is loaded. Now that I've 'fixed' the problem of topguh/main matching, I now have an eternal loop that constantly reloads the 'main' page. Here's the code (indented for easy reading):

in top_sitemap.html
Code:
onLoad="
if (parent.main.location != 'sitemap.html')
   parent.main.location='sitemap.html'
"

in sitemap.html
Code:
onLoad="
if ((top == null) || (top == self)) {
   top.location='init_webs.html'
}
else
   parent.topguh.location='top_sitemap.html'
};"

sitemap.html (v2)
Code:
onLoad="
if ((top == null) || (top == self)) {
   top.location='init_sitemap.html'
} 
else { if (parent.topguh.location != 'top_sitemap.html') 
   parent.topguh.location='top_sitemap.html'
};"
I'm pretty sure the problem is with the code in the top_sitemap.html, but I can't figure it out, and I'm even getting a little confused.
 
Location strings don't just contain the last part of the name, but the entire uri path. Just because you don't specify it doesn't mean it isn't there - it adds the current base uri to any relative path you give, and that is what actually gets stored in the location object.

Try using a regular-expression match instead:
Code:
if (parent.main.location.href.match(/sitemap.html$/)) { ... }
This applies to both points where you check against the uri by name.
 
Additionally, you could use the indexOf function:

Code:
onLoad="
if (parent.main.location.indexOf('sitemap.html') == -1 )
   parent.main.location='[URL unfurl="true"]http://full.path.tosite/sitemap.html'[/URL]
"
Code:
onLoad="
if ((top == null) || (top == self)) {
   top.location='[URL unfurl="true"]http://full.path.tosite/init_webs.html'[/URL]
}
else
   parent.topguh.location='[URL unfurl="true"]http://full.path.tosite/top_sitemap.html'[/URL]
};"
Code:
onLoad="
if ((top == null) || (top == self)) {
   top.location='[URL unfurl="true"]http://full.path.tosite/init_sitemap.html'[/URL]
}
else { if (parent.topguh.location.indexOf('top_sitemap.html') == -1)
   parent.topguh.location='[URL unfurl="true"]http://full.path.tosite/top_sitemap.html'[/URL]
};"

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I tried MOrac's way, still loops. Then I tried cLFlaVA's way, I get "object doesn't support this property or method". I think the 'if frame shows wrong page' statment isn't checking properly, causing it to execute everytime even though it's actually the right page. Either the syntax is wrong, or it's bad logic. I don't even really need the else {if..} either, but why do something that doesn't need to be done?

...but the problem statement I believe is:
onLoad="if (parent.main.location != 'sitemap.html') {parent.main.location='sitemap.html'};"
in top_sitemap.html.

I also tried various variations and combinations of the two proposed solutions.. nothing.
 
Plus I discovered another problem, (because the other one just wasn't enuf):
When init_sitemap.html is navigated to from the title page which is not in frames, this error occurs in top_sitemap.html:
'parent.main.location' is null or is not an object
Is it because the page hasn't been loaded into 'main' yet at that point? It seems obvious why, but not so obvious how to fix.
 
'main' is a frame. frames['main'] works fine as well; and so does using the file name alone, it always has. The whole site was originally made using relative URL's. If it's required, What would I use instead of ' for offline testing using local HD paths? I'm not uploading anything until it's done and proper.
 
I think I got it now! The relative URLs only work in normal HTML links and such. But for the comparison in javascript, it needs the entire URL.

ignore my last post, (maybe even delete it? -> mod) I found out how:

file:///C:/My%20Documents/page.html

now, when I upload it, just gotta be sure all the urls are http://
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top