Go directly to desired page, in JavaScript

Discussion in 'Javascript' started by Bert Visscher, Aug 10, 2004.

  1. Hello everyone,

    I would like to let visitors of my website be able to go directly to a
    desired page, by using a URL like www.example.com?progname. I thought I
    could do this as follows:

    <html>
    <frameset rows="88,*">
    <frame name="head" noresize src="head.htm" />
    <frameset cols="152,*">
    <frame name="menu" noresize src="menu.htm" />
    <script language="JavaScript">
    prog = location.search
    prog = prog.substr(1)
    prog = prog.split("&")
    if (prog=="progname") { document.write ("<frame name='body' noresize
    src='progpage.htm' />") }
    else if (prog==...
    ....
    else { document.write ('<frame name="body" noresize src="mainpage.htm"
    />') }
    </script>
    </frameset>
    </frameset>
    </html>

    I see that the above code doesn't produce a page for the body, but I can't
    see why? Could anybody please tell me what I'm overlooking?

    TIA and regards, Bert Visscher.
     
    Bert Visscher, Aug 10, 2004
    #1
    1. Advertising

  2. Bert Visscher

    Evertjan. Guest

    Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    > prog = prog.split("&")
    > if (prog=="progname") {


    [follow up to: comp.lang.javascript]

    Dag Bert,

    prog is not a string but an array.
    If the calling url was:

    http://mySite.nl/test.html?x=progname&y=blah

    if (prog[0] == "x=progname") {


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 10, 2004
    #2
    1. Advertising

  3. Dag Evertjan,

    The way I interpret your reply, the following code should work:

    <html>
    <frameset rows="88,*">
    <frame name="kop" noresize src="kop.htm" />
    <frameset cols="152,*">
    <frame name="menu" noresize src="menu.htm" />
    <script language="JavaScript">
    prog = location.search
    prog = prog.substr(1)
    prog = prog.split("&")
    if (prog[0]=="gezondheidslijn") { document.write ("<frame name='body'
    src='pi-gezondheidslijn.htm' />") }
    else { document.write ("<frame name='body' src='hoofdpagina.htm' />") }
    </script>
    </frameset>
    </frameset>
    </html>

    I'm afraid it doesn't. Just like before, I see the top and left frame
    appear, but there's no body.

    TIA and regards, Bert V.

    "Evertjan." <> schreef in bericht
    news:Xns954170A4145DFeejj99@194.109.133.29...
    > Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    > > prog = prog.split("&")
    > > if (prog=="progname") {

    >
    > [follow up to: comp.lang.javascript]
    >
    > Dag Bert,
    >
    > prog is not a string but an array.
    > If the calling url was:
    >
    > http://mySite.nl/test.html?x=progname&y=blah
    >
    > if (prog[0] == "x=progname") {
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    Bert Visscher, Aug 10, 2004
    #3
  4. Bert Visscher

    Evertjan. Guest

    Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    > "Evertjan." <> schreef in bericht
    > news:Xns954170A4145DFeejj99@194.109.133.29...
    >> Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    >> > prog = prog.split("&")
    >> > if (prog=="progname") {

    >>
    >> [follow up to: comp.lang.javascript]
    >>
    >> Dag Bert,
    >>
    >> prog is not a string but an array.
    >> If the calling url was:
    >>
    >> http://mySite.nl/test.html?x=progname&y=blah
    >>
    >> if (prog[0] == "x=progname") {
    >>

    > The way I interpret your reply, the following code should work:
    >
    > <html>
    > <frameset rows="88,*">
    > <frame name="kop" noresize src="kop.htm" />
    > <frameset cols="152,*">
    > <frame name="menu" noresize src="menu.htm" />
    > <script language="JavaScript">
    > prog = location.search
    > prog = prog.substr(1)
    > prog = prog.split("&")
    > if (prog[0]=="gezondheidslijn") { document.write ("<frame
    > name='body'
    > src='pi-gezondheidslijn.htm' />") }
    > else { document.write ("<frame name='body' src='hoofdpagina.htm'
    > />") }
    > </script>
    > </frameset>
    > </frameset>
    > </html>
    >
    > I'm afraid it doesn't. Just like before, I see the top and left frame
    > appear, but there's no body.


    This
    = if (prog[0]=="gezondheidslijn") =
    would require zoiets als:
    http://mySite.nl/test.html?gezondheidslijn&y=blah
    This cannot be the output of a <form>

    Do you get javascript errors ?

    Please start debugging by inserting a handful of alert()s:

    <frame name='body'
    <script type="text/JavaScript"> // the 'language=' is depriciated
    var prog = location.search
    alert(prog) // is there a & in the string ???
    prog = prog.substr(1)
    alert(prog) // do you see the same without the '?' ?
    prog = prog.split("&")
    alert(prog[0]) // do you see 'gezondheidslijn' ?
    if (prog[0]=="gezondheidslijn"){
    alert('ja') // 'if' is given true
    document.write("src='pi-gezondheidslijn.htm'")
    }
    else {
    alert('nee') // false
    document.write("src='hoofdpagina.htm'")
    }
    </script>
    />

    Are the two links correct ?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 10, 2004
    #4
  5. "Evertjan." <> schreef in bericht
    news:Xns9541E57C1FE97eejj99@194.109.133.29...
    > Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    > > "Evertjan." <> schreef in bericht
    > > news:Xns954170A4145DFeejj99@194.109.133.29...
    > >> Bert Visscher wrote on 10 aug 2004 in comp.lang.javascript:
    > >> > prog = prog.split("&")
    > >> > if (prog=="progname") {
    > >>
    > >> [follow up to: comp.lang.javascript]
    > >>
    > >> Dag Bert,
    > >>
    > >> prog is not a string but an array.
    > >> If the calling url was:
    > >>
    > >> http://mySite.nl/test.html?x=progname&y=blah
    > >>
    > >> if (prog[0] == "x=progname") {
    > >>

    > > The way I interpret your reply, the following code should work:
    > >
    > > <html>
    > > <frameset rows="88,*">
    > > <frame name="kop" noresize src="kop.htm" />
    > > <frameset cols="152,*">
    > > <frame name="menu" noresize src="menu.htm" />
    > > <script language="JavaScript">
    > > prog = location.search
    > > prog = prog.substr(1)
    > > prog = prog.split("&")
    > > if (prog[0]=="gezondheidslijn") { document.write ("<frame
    > > name='body'
    > > src='pi-gezondheidslijn.htm' />") }
    > > else { document.write ("<frame name='body' src='hoofdpagina.htm'
    > > />") }
    > > </script>
    > > </frameset>
    > > </frameset>
    > > </html>
    > >
    > > I'm afraid it doesn't. Just like before, I see the top and left frame
    > > appear, but there's no body.

    >
    > This
    > = if (prog[0]=="gezondheidslijn") =
    > would require zoiets als:
    > http://mySite.nl/test.html?gezondheidslijn&y=blah
    > This cannot be the output of a <form>
    >
    > Do you get javascript errors ?
    >
    > Please start debugging by inserting a handful of alert()s:
    >
    > <frame name='body'
    > <script type="text/JavaScript"> // the 'language=' is depriciated
    > var prog = location.search
    > alert(prog) // is there a & in the string ???
    > prog = prog.substr(1)
    > alert(prog) // do you see the same without the '?' ?
    > prog = prog.split("&")
    > alert(prog[0]) // do you see 'gezondheidslijn' ?
    > if (prog[0]=="gezondheidslijn"){
    > alert('ja') // 'if' is given true
    > document.write("src='pi-gezondheidslijn.htm'")
    > }
    > else {
    > alert('nee') // false
    > document.write("src='hoofdpagina.htm'")
    > }
    > </script>
    > />
    >
    > Are the two links correct ?


    Hoi Evertjan,

    I flipped a couple of quotes, and ended up with the following complete code:

    <html>
    <frameset rows="88,*">
    <frame name="kop" noresize src="kop.htm" />
    <frameset cols="152,*">
    <frame name="menu" noresize src="menu.htm" />
    <frame name="body"
    <script type="text/JavaScript">
    var prog = location.search
    alert(prog) // is there a & in the string ???
    prog = prog.substr(1)
    alert(prog) // do you see the same without the '?' ?
    prog = prog.split("&")
    alert(prog[0]) // do you see 'gezondheidslijn' ?
    if (prog[0]=="gezondheidslijn")
    {
    alert("ja") // 'if' is given true
    document.write('src="pi-gezondheidslijn.htm"')
    }
    else
    {
    alert("nee") // false
    document.write('src="hoofdpagina.htm"')
    }
    </script>
    />
    </frameset>
    </frameset>
    </html>

    I think we're getting closer:
    This time around, regardless of whether I add "?gezondheidslijn", I get a
    body...but it stays blank. And, as if that's not curious enough, I'm not
    getting any of the alerts.

    Oh, I nearly forgot to write that I'm not getting any error messages.

    TIA and regards, Bert V.
     
    Bert Visscher, Aug 12, 2004
    #5
  6. Bert Visscher

    Evertjan. Guest

    Bert Visscher wrote on 12 aug 2004 in comp.lang.javascript:
    > I think we're getting closer:
    > This time around, regardless of whether I add "?gezondheidslijn", I
    > get a body...but it stays blank. And, as if that's not curious enough,
    > I'm not getting any of the alerts.
    >
    > Oh, I nearly forgot to write that I'm not getting any error messages.


    Tja, Bert, dan wordt de hele script niet uitgevoerd in een frame
    declaratie!!!

    Dit werkt wel:

    <html>

    <script type="text/JavaScript">
    function kies(x){
    myBody.location.href=
    (location.search.substr(1).split("&")[0]==
    "gezondheidslijn")
    ?"pi-gezondheidslijn.htm":"hoofdpagina.htm"
    }
    </script>

    <frameset rows="88,*" onLoad="kies()">
    <frame name="kop" noresize src="kop.htm" />
    <frameset cols="152,*">
    <frame name="menu" noresize src="menu.htm" />
    <frame name="myBody" />
    </frameset>
    </frameset>

    </html>

    [ik heb de code sterk verkort en de naam "body" vervangen,
    omdat dat soms een "reserved word" zou kunnen zijn.]


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 12, 2004
    #6
  7. > I think we're getting closer:
    > This time around, regardless of whether I add "?gezondheidslijn", I get a
    > body...but it stays blank. And, as if that's not curious enough, I'm not
    > getting any of the alerts.
    >
    > Oh, I nearly forgot to write that I'm not getting any error messages.
    >
    > TIA and regards, Bert V.


    I had a similar problem. I got it to work with iframes using the
    following:

    <script language="JavaScript">
    page = "main.htm"; //default page
    if(location.search) page = location.search.substring(1);

    //insert extra logic here if want

    document.write('<iframe src="' + page + '" id="myIframe"
    name="myIframe" width="630" scrolling="no"
    frameborder="1"></iframe>');
    </script>

    You could add logic in there, like:

    if (page = "help") page = help.html;

    I hope this helps.

    Jim
     
    Jim Marquardson, Aug 12, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bg
    Replies:
    0
    Views:
    115
  2. Jack
    Replies:
    3
    Views:
    135
    Paxton
    Nov 12, 2004
  3. techy techno
    Replies:
    0
    Views:
    117
    techy techno
    Feb 4, 2004
  4. Alexander
    Replies:
    1
    Views:
    632
    Grunken
    Apr 21, 2004
  5. Deryck
    Replies:
    7
    Views:
    105
Loading...

Share This Page