🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.javascript
Article #61

Re: Help needed with script for loading right page

#61
From: T. Postel
Date: Mon, 29 May 2000 00:00
73 lines
3144 bytes
In article <3932a6c2.2214143@news.arnhem.chello.nl>, e.vroekel@chello.nl 
(Erik van Roekel) wrote:
>
>
>I'm using Netobjects Fusion (NOF) for developing my site and I'm using
>frames. For every page NOF generates 3 files a name.html (the
>mainpage) and two pages which defines the frames used called
>body_name.html and header_name.html. (name could be any name).
>
>The pages which start with body_ or header_ shouldn't be loaded
>individually. So I'm looking for a javascript which redirect the user
>if necessary.
>
>If a user loads a page and the name of that page starts with "body_"
>or "header_" the user has to be redirect to the name used without
>"body_" or "header_" in this case index.html. 
>
>One script for all pages independent if the right page is named
>index.html or info.htm
>
>Procedure:
>1. Check if the page starts with "header_" if so go to step 4
>2. Check if the page starts with "body_" if so go to step 4
>3. Quit
>4. Load the right page by deleting "header_" or "body_" in the URL
>used and
>loading the new corrected url.
>
>Any Javascript expert who can solve this case ?
>
>Regards,
>Erik
>
If I understand what you want, I think you could use something like 
this. This is based on some working script I have used, but I didn't 
test it.  The frame page can check to see if it has the correct parent. 
If you put this in the <head> section of each frame page 
("body_page.html") it will load the correct frameset:

<script language="javascript">
if(top == self) {
  s = self.location.href
  i = s.indexOf("body_") 
  if (i)=> 0) {
    temp = s.substr(i+5) + "?" + s.substr(i)
    }  
  i = s.indexOf("header_")
  if (i)=> 0) {
    temp = s.substr(i+7) + "?" + s.substr(i)
    } 
document.location.href = temp
}
</script>

If you put this in the frameset page and call it with a <body 
onLoad="loadPage()...> it will load the correct page in the header or 
body:

<script language="javascript">
function loadPage() {
var temp = document.location.href.split("?")
  if ((temp[1].indexOf("header_") { parent.header.location.href = 
temp[1] }
  if ((temp[1].indexOf("body_") { parent.body.location.href = temp[1] }
}
</script>

good luck.


-- 
While my e-mail address is not munged,     | T.Postel@ieee.org
I probably won't read anything sent there. |
Technical Details
Message-ID: <TcCY4.49$pY6.2580@news2.randori.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3932a6c2.2214143@news.arnhem.chello.nl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10731d,ac786e1d7d671cb8
X-Google-Attributes: gid10731d,public
X-Google-Thread: 10bacc,ac786e1d7d671cb8
X-Google-Attributes: gid10bacc,public
X-Google-Thread: fb3cb,ac786e1d7d671cb8
X-Google-Attributes: gidfb3cb,public
From: T.Postel@ieee.org (T. Postel)
Subject: Re: Help needed with script for loading right page
Date: 2000/05/29
Message-ID: <TcCY4.49$pY6.2580@news2.randori.com>
X-Deja-AN: 628783492
References: <3932a6c2.2214143@news.arnhem.chello.nl>
X-Trace: news2.randori.com 959639475 207.211.62.184 (Mon, 29 May 2000 15:31:15 PDT)
Organization: division-7.com
NNTP-Posting-Date: Mon, 29 May 2000 15:31:15 PDT
Newsgroups: comp.lang.javascript,borland.public.intrabuilder.javascript,comp.lang.java.javascript