CGI parameters (or equivalent) in Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew C.

    CGI parameters (or equivalent) in Javascript


    First time posting to this forum, so hello everyone!

    Does anyone know a way of passing parameters into a Javascript script 'from
    outside' via additions to the URL -- similar to (or even the same as!) the
    idea of CGI parameters?

    Thanks for any info!

    A.


  • Evertjan.

    #2
    Re: CGI parameters (or equivalent) in Javascript

    Andrew C. wrote on 19 jan 2004 in comp.lang.javas cript:[color=blue]
    > Does anyone know a way of passing parameters into a Javascript script
    > 'from outside' via additions to the URL -- similar to (or even the
    > same as!) the idea of CGI parameters?[/color]

    Don't know about CGI-parameters,
    but if you want the querystring,
    try this as a html file:


    <a href="?a=2">cli ck here</a><br>
    <SCRIPT>
    document.write( location.search )
    </SCRIPT>


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

    Comment

    • Andrew C.

      #3
      Re: CGI parameters (or equivalent) in Javascript

      [color=blue][color=green]
      > > Does anyone know a way of passing parameters into a Javascript script
      > > 'from outside' via additions to the URL -- similar to (or even the
      > > same as!) the idea of CGI parameters?[/color]
      >
      > Don't know about CGI-parameters,
      > but if you want the querystring,
      > try this as a html file:
      >
      > <a href="?a=2">cli ck here</a><br>
      > <SCRIPT>
      > document.write( location.search )
      > </SCRIPT>[/color]

      That looks like it might do the trick, so thanks!

      However, I was talking to a friend of mine about the same problem, and he
      said he doubted there'd be any way of doing it because the web server won't
      make CGI params (the stuff from '?' onwards in a URL) available to the
      client.

      May I ask if you've actually deployed this 'location.searc h' thing into a
      live website and seen it happen?

      A.


      Comment

      • Michael Winter

        #4
        Re: CGI parameters (or equivalent) in Javascript

        On Mon, 19 Jan 2004 13:30:49 GMT, Andrew C. <dummy@andrewco rnes.com> wrote:
        [color=blue]
        > Does anyone know a way of passing parameters into a Javascript script
        > 'from outside' via additions to the URL -- similar to (or even the
        > same as!) the idea of CGI parameters?[/color]

        What you are referring to is the "search part" of HTTP URLs[1].

        You can retrieve it with the Location.search property. This will return
        everything in the URL from the question mark (?) onwards. For example,

        Current page URL:


        window.location .search:
        ?init=true&logg edin=false

        Mike


        [1] Synonymous with the GET method in HTML form submission, and the
        "query" or "search" string in JavaScript.

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Michael Winter

          #5
          Re: CGI parameters (or equivalent) in Javascript

          On Mon, 19 Jan 2004 16:13:18 GMT, Andrew C. <dummy@andrewco rnes.com> wrote:
          [color=blue]
          > May I ask if you've actually deployed this 'location.searc h' thing into a
          > live website and seen it happen?[/color]

          I've used it to dynamically create a document (I didn't have server-side
          support, unfortunately). It will work.

          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • Lee

            #6
            Re: CGI parameters (or equivalent) in Javascript

            Andrew C. said:[color=blue]
            >
            >[color=green][color=darkred]
            >> > Does anyone know a way of passing parameters into a Javascript script
            >> > 'from outside' via additions to the URL -- similar to (or even the
            >> > same as!) the idea of CGI parameters?[/color]
            >>
            >> Don't know about CGI-parameters,
            >> but if you want the querystring,
            >> try this as a html file:
            >>
            >> <a href="?a=2">cli ck here</a><br>
            >> <SCRIPT>
            >> document.write( location.search )
            >> </SCRIPT>[/color]
            >
            >That looks like it might do the trick, so thanks!
            >
            >However, I was talking to a friend of mine about the same problem, and he
            >said he doubted there'd be any way of doing it because the web server won't
            >make CGI params (the stuff from '?' onwards in a URL) available to the
            >client.
            >
            >May I ask if you've actually deployed this 'location.searc h' thing into a
            >live website and seen it happen?[/color]

            It's done all the time. The entire URL is always available.
            The location.search attribute is really just an added convenience.

            Comment

            • Andrew C.

              #7
              Re: CGI parameters (or equivalent) in Javascript


              Thanks to all for the useful responses! :)

              A.


              Comment

              • Evertjan.

                #8
                Re: CGI parameters (or equivalent) in Javascript

                Andrew C. wrote on 19 jan 2004 in comp.lang.javas cript:[color=blue][color=green][color=darkred]
                >> > Does anyone know a way of passing parameters into a Javascript
                >> > script 'from outside' via additions to the URL -- similar to (or
                >> > even the same as!) the idea of CGI parameters?[/color]
                >>
                >> Don't know about CGI-parameters,
                >> but if you want the querystring,
                >> try this as a html file:
                >>
                >> <a href="?a=2">cli ck here</a><br>
                >> <SCRIPT>
                >> document.write( location.search )
                >> </SCRIPT>[/color]
                >
                > That looks like it might do the trick, so thanks!
                >
                > However, I was talking to a friend of mine about the same problem, and
                > he said he doubted there'd be any way of doing it because the web
                > server won't make CGI params (the stuff from '?' onwards in a URL)
                > available to the client.
                >
                > May I ask if you've actually deployed this 'location.searc h' thing
                > into a live website and seen it happen?[/color]

                A strange question.
                I just showed you how it is done.

                Why don't you try it yourself?


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

                Comment

                Working...