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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect Url if page has no frames 2

Status
Not open for further replies.

mal54

Programmer
Mar 11, 2002
13
AU
Hi
I find that if somebody types directly into the address field on a browser the full Url say that the user gets the page without frames. Ok so I get this here code

<SCRIPT language=&quot;javascript&quot;>
<!--
if (parent.frames.length == 0) {
top.location.href=&quot;default.htm?start=/search/index.asp&quot;
}
//-->
</SCRIPT>

it should take the user to the search/index.asp page and provide the frames see. Well it don't F**k it gets the frames Ok but not the search/index.asp I get the main/default.htm instead. Bloody hell what a f***ing mouthfull.
Anyway can you help
Mal
 
put this in the <head> of your frameset page:
Code:
<script type=&quot;text/javascript&quot;>
window.onload = function checkUrl() {
    var qs = parent.location.search.split(/start=/i);
    if (qs.length > 1) {
        parent.frames[1].location = qs[1];
    }
}
</script>

it's currently set up to change the location of the second frame. (frames[1])

use it like so:


NOTES:
- during testing, I noticed that IE didn't like absolute URLs like &quot; locally, but they worked fine from a webserver.

- i'm using window.onload, so if you have anything in <body onload> we'll have to modify it slightly



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thanks Jeff
I have received your kind work and thank you sincerly.

I added the script to the <head> of the frame set as instructed and now find I have the head frame and the main pages visible, however the left nav page is not visible.
I guess I should have mentioned the page is a three frame set. I'm not sure if the problem is your program or my lack of understanding of frame sets.
Anyway you can see the site at check it out if you can help let me know.

Mal
and thanks again
 
hi mal,

i can't quite figure out how your site is layed out - i see that you have 3 frames, but your frameset only defines two: &quot;banner&quot; and &quot;MainNav&quot;. where is the body frame defined?

in my experience with frames, your frameset should be like so:

<frameset rows=&quot;120,*&quot;>
<frame name=&quot;banner&quot;...
<frameset cols=&quot;120,*&quot;>
<frame name=&quot;MainNav&quot;...
<frame name=&quot;MainBody&quot;...
</frameset>
</frameset>

anyway, regardless of how you have it working, if you've named your body frame then you can change the script to this:

<script type=&quot;text/javascript&quot;>
window.onload = function checkUrl() {
var qs = parent.location.search.split(/start=/i);
if (qs.length > 1) {
parent.frameNameHere.location = qs[1];
}
}
</script>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thanks Jeff
You have made my day. The problem was in the design of the pages that made up the default page. It had as you discovered only two frames, one of which, the body, was made up of another page with two frames the left nav and the body. I scraped the whole default page and set three frames to it a new page the head left nav and body. And your function works well.
Sincere thanks to you.

If you have the time I have another, I hope, small problem with dates on the site. My ISP for some reason moved my site to a US based server and the dates are all in US format and around 15 hours behind AEST. I know it is possible to refer to GMT but I haven't been able to find the syntax.
Can you help
Mal
 
you can use:

Date.toUTCString();
Date.getUTCSeconds();
Date.getUTCMinutes();
Date.getUTCHours();
Date.getUTCDate();
Date.getUTCDay();
Date.getUTCMonth();
Date.getUTCFullYear();



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
How would someone modify the script:

Code:
<script type=&quot;text/javascript&quot;>
window.onload = function checkUrl() {
  var qs = parent.location.search.split(/start=/i);
  if (qs.length > 1) {
    parent.[b]framename[/b].location = qs[1];
  }
}
</script>
for use on a regular HTML page, not an asp page? Basically, I want to redirect a typed URL back into my frames, then locate the main frame to the page they were seeking. All pages are HTML, and there are no &quot;?&quot; in the addresses. Real simple, but no idea how to modify the script above to fit.
 
randyQ,

this will work regardless of the type of page. you place the script above in your frameset page, then each frame body page would include this:
Code:
<SCRIPT type=&quot;text/javascript&quot;>
<!--
if (parent.frames.length == 0) {
    top.location.href=&quot;[URL unfurl="true"]http://www.mySite.com/frameset.html?start=thisFrame.html&quot;;[/URL]
}
//-->
</SCRIPT>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
This is just what I'm trying to do, thanks. However it's not quite working for me, and I'm pretty certain it's because I'm not referencing the right frame (with the existing code).

My frameset looks like this:
Code:
<frameset rows=&quot;*&quot; cols=&quot;125,*&quot; frameborder=&quot;NO&quot; border=&quot;0&quot; framespacing=&quot;0&quot;>
    <frame src=&quot;leftframe.htm&quot; name=&quot;leftFrame&quot; scrolling=&quot;NO&quot; noresize>
    <frameset rows=&quot;95,*&quot; frameborder=&quot;NO&quot; border=&quot;0&quot; framespacing=&quot;0&quot;>
        <frame src=&quot;topframe.htm&quot; name=&quot;topFrame&quot; scrolling=&quot;NO&quot; noresize>
        <frame src=&quot;Catalog.htm&quot; name=&quot;mainFrame&quot;>
    </frameset>
</frameset>
I know that the wrong frameset for me is referenced in the code previously posted:
Code:
<script type=&quot;text/javascript&quot;>
window.onload = function checkUrl() {
    var qs = parent.location.search.split(/start=/i);
    if (qs.length > 1) {
        parent.frames[1].location = qs[1];
    }
}
</script>
I'm not quite certain how the references work. How would I change the
Code:
parent.frames
line to target my &quot;mainFrame&quot;?

Thanks in advance.
 
genimuse,

you should be able to replace the line
parent.frames[1].location = qs[1];

with
parent.frames[2].location = qs[1];

or
parent.mainFrame.location = qs[1];



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thank you, those were my guesses. Unfortunately I'm still getting the default page in the mainFrame with both of those.

I know for certain that my URL is ending up correctly (mydomain.com/myFrameName.htm?start=myDesiredPage.htm), but no go. Any thoughts on what else might be wrong? The code I posted above is copied straight out of my page.
 
ok, i did some testing and discovered the following: make sure the <script> block comes BEFORE your <frameset> block.

also, if you have anything in window.onload or body onload anywhere else, we'll have to make some changes.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Wait...Now it's working...Must ahve been cached...heh heh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top