Go directly to desired page, in JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bert Visscher

    Go directly to desired page, in JavaScript

    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="JavaS cript">
    prog = location.search
    prog = prog.substr(1)
    prog = prog.split("&")
    if (prog=="prognam e") { document.write ("<frame name='body' noresize
    src='progpage.h tm' />") }
    else if (prog==...
    ....
    else { document.write ('<frame name="body" noresize src="mainpage.h tm"
    />') }
    </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.


  • Evertjan.

    #2
    Re: Go directly to desired page, in JavaScript

    Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:[color=blue]
    > prog = prog.split("&")
    > if (prog=="prognam e") {[/color]

    [follow up to: comp.lang.javas cript]

    Dag Bert,

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



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


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Andrew Thompson

      #3
      Re: Go directly to desired page, in JavaScript

      On Tue, 10 Aug 2004 10:25:18 +0200, Bert Visscher wrote:
      [color=blue]
      > I would like to let visitors of my website..[/color]

      URL?

      BTW ... alive.internet. lang.javascript ,
      (never heard of it..)
      alt.comp.lang.j avascript,
      (what a load of crap..)
      comp.lang.java. javascript,
      (not an official group..)
      comp.lang.javas cript
      (Ahhhh.. yes, this is where the JS gurus reside)

      Please do not cross-post to 4 separate groups..
      You may think your problem is that important,
      others know it is not.
      <http://www.physci.org/codes/javafaq.jsp#xpo st>

      Follow ups for this thread set to c.l.js ONLY..

      [ Please note that even to post *this* message to
      four groups has my newsreader whining at me.. ]

      --
      Andrew Thompson
      http://www.PhySci.org/ Open-source software suite
      http://www.PhySci.org/codes/ Web & IT Help
      http://www.1point1C.org/ Science & Technology

      Comment

      • Bert Visscher

        #4
        Re: Go directly to desired page, in JavaScript

        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="JavaS cript">
        prog = location.search
        prog = prog.substr(1)
        prog = prog.split("&")
        if (prog[0]=="gezondheidsl ijn") { document.write ("<frame name='body'
        src='pi-gezondheidslijn .htm' />") }
        else { document.write ("<frame name='body' src='hoofdpagin a.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." <exjxw.hannivoo rt@interxnl.net > schreef in bericht
        news:Xns954170A 4145DFeejj99@19 4.109.133.29...[color=blue]
        > Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:[color=green]
        > > prog = prog.split("&")
        > > if (prog=="prognam e") {[/color]
        >
        > [follow up to: comp.lang.javas cript]
        >
        > 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)[/color]


        Comment

        • Evertjan.

          #5
          Re: Go directly to desired page, in JavaScript

          Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:[color=blue]
          > "Evertjan." <exjxw.hannivoo rt@interxnl.net > schreef in bericht
          > news:Xns954170A 4145DFeejj99@19 4.109.133.29...[color=green]
          >> Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:[color=darkred]
          >> > prog = prog.split("&")
          >> > if (prog=="prognam e") {[/color]
          >>
          >> [follow up to: comp.lang.javas cript]
          >>
          >> 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 ") {
          >>[/color]
          > 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="JavaS cript">
          > prog = location.search
          > prog = prog.substr(1)
          > prog = prog.split("&")
          > if (prog[0]=="gezondheidsl ijn") { document.write ("<frame
          > name='body'
          > src='pi-gezondheidslijn .htm' />") }
          > else { document.write ("<frame name='body' src='hoofdpagin a.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.[/color]

          This
          = if (prog[0]=="gezondheidsl ijn") =
          would require zoiets als:

          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 'gezondheidslij n' ?
          if (prog[0]=="gezondheidsl ijn"){
          alert('ja') // 'if' is given true
          document.write( "src='pi-gezondheidslijn .htm'")
          }
          else {
          alert('nee') // false
          document.write( "src='hoofdpagi na.htm'")
          }
          </script>
          />

          Are the two links correct ?


          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • Bert Visscher

            #6
            Re: Go directly to desired page, in JavaScript


            "Evertjan." <exjxw.hannivoo rt@interxnl.net > schreef in bericht
            news:Xns9541E57 C1FE97eejj99@19 4.109.133.29...[color=blue]
            > Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:[color=green]
            > > "Evertjan." <exjxw.hannivoo rt@interxnl.net > schreef in bericht
            > > news:Xns954170A 4145DFeejj99@19 4.109.133.29...[color=darkred]
            > >> Bert Visscher wrote on 10 aug 2004 in comp.lang.javas cript:
            > >> > prog = prog.split("&")
            > >> > if (prog=="prognam e") {
            > >>
            > >> [follow up to: comp.lang.javas cript]
            > >>
            > >> 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 ") {
            > >>[/color]
            > > 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="JavaS cript">
            > > prog = location.search
            > > prog = prog.substr(1)
            > > prog = prog.split("&")
            > > if (prog[0]=="gezondheidsl ijn") { document.write ("<frame
            > > name='body'
            > > src='pi-gezondheidslijn .htm' />") }
            > > else { document.write ("<frame name='body' src='hoofdpagin a.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.[/color]
            >
            > This
            > = if (prog[0]=="gezondheidsl ijn") =
            > 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 'gezondheidslij n' ?
            > if (prog[0]=="gezondheidsl ijn"){
            > alert('ja') // 'if' is given true
            > document.write( "src='pi-gezondheidslijn .htm'")
            > }
            > else {
            > alert('nee') // false
            > document.write( "src='hoofdpagi na.htm'")
            > }
            > </script>
            > />
            >
            > Are the two links correct ?[/color]

            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 'gezondheidslij n' ?
            if (prog[0]=="gezondheidsl ijn")
            {
            alert("ja") // 'if' is given true
            document.write( 'src="pi-gezondheidslijn .htm"')
            }
            else
            {
            alert("nee") // false
            document.write( 'src="hoofdpagi na.htm"')
            }
            </script>
            />
            </frameset>
            </frameset>
            </html>

            I think we're getting closer:
            This time around, regardless of whether I add "?gezondheidsli jn", 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.


            Comment

            • Evertjan.

              #7
              Re: Go directly to desired page, in JavaScript

              Bert Visscher wrote on 12 aug 2004 in comp.lang.javas cript:[color=blue]
              > I think we're getting closer:
              > This time around, regardless of whether I add "?gezondheidsli jn", 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.[/color]

              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.searc h.substr(1).spl it("&")[0]==
              "gezondheidslij n")
              ?"pi-gezondheidslijn .htm":"hoofdpag ina.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)

              Comment

              • Jim Marquardson

                #8
                Re: Go directly to desired page, in JavaScript

                > I think we're getting closer:[color=blue]
                > This time around, regardless of whether I add "?gezondheidsli jn", 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.[/color]

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

                <script language="JavaS cript">
                page = "main.htm"; //default page
                if(location.sea rch) 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

                Comment

                Working...