How do I retrieve a URL into a variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Szabo

    #1

    How do I retrieve a URL into a variable?


    I like to know if there is a JS function to retrieve a URL into a variable

    cURL = somefunction("h ttp://www.domain.com" );

    Is there something like this?

    TIA,

    Tom


  • McKirahan

    #2
    Re: How do I retrieve a URL into a variable?

    "Tom Szabo" <tom@intersoft. net.au> wrote in message
    news:419b3832$1 @dnews.tpgi.com .au...[color=blue]
    >
    > I like to know if there is a JS function to retrieve a URL into a variable
    >
    > cURL = somefunction("h ttp://www.domain.com" );
    >
    > Is there something like this?
    >
    > TIA,
    >
    > Tom[/color]

    By "retrieve a URL" do you mean of the page containing the JS?

    <html>
    <head>
    <title>loc~href .htm</title>
    <script type="text/javascript">
    var url = document.locati on.href;
    document.write( url);
    </script>
    </head>
    <body>
    </body>
    </html>


    Comment

    • Andrew Thompson

      #3
      Re: How do I retrieve a URL into a variable?

      On Wed, 17 Nov 2004 12:31:43 GMT, McKirahan wrote:
      [color=blue]
      > "Tom Szabo" <tom@intersoft. net.au> wrote in message
      > news:419b3832$1 @dnews.tpgi.com .au...[color=green]
      >>
      >> I like to know if there is a JS function to retrieve a URL into a variable
      >>
      >> cURL = somefunction("h ttp://www.domain.com" );[/color][/color]
      ....[color=blue]
      > By "retrieve a URL" do you mean of the page containing the JS?[/color]

      I suspect the OP is actually referring to retrieving the content
      of another URL (than the page itself) into a JS var as text.

      --
      Andrew Thompson
      http://www.PhySci.org/codes/ Web & IT Help
      http://www.PhySci.org/ Open-source software suite
      http://www.1point1C.org/ Science & Technology
      http://www.LensEscapes.com/ Images that escape the mundane

      Comment

      • Tom Szabo

        #4
        Re: How do I retrieve a URL into a variable?

        > By "retrieve a URL" do you mean of the page containing the JS?

        I could be using the wrong terminology, what I ment is to get the content of
        the web page the URL pointing to....so

        var "url" would contain something like:

        "<html>
        <head>
        .....

        ......
        /html>"

        Am I making sense? sorry if still not ....

        TIA,

        Tom



        Comment

        • Michael Winter

          #5
          Re: How do I retrieve a URL into a variable?

          On Wed, 17 Nov 2004 22:34:50 +1000, Tom Szabo <tom@intersoft. net.au> wrote:

          [snip]
          [color=blue]
          > I could be using the wrong terminology, what I ment is to get the
          > content of the web page the URL pointing to....so[/color]

          Please read the FAQ (<URL:http://jibbering.com/faq/>). Your question is
          answered there.

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Tom Szabo

            #6
            Re: How do I retrieve a URL into a variable?

            > >> cURL = somefunction("h ttp://www.domain.com" );[color=blue]
            > ...[color=green]
            > > By "retrieve a URL" do you mean of the page containing the JS?[/color]
            >
            > I suspect the OP is actually referring to retrieving the content
            > of another URL (than the page itself) into a JS var as text.[/color]

            YES, correct, that is what I like to do...


            Comment

            • Tom Szabo

              #7
              Re: How do I retrieve a URL into a variable?


              "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
              news:opshl090ol x13kvk@atlantis ...[color=blue]
              > On Wed, 17 Nov 2004 22:34:50 +1000, Tom Szabo <tom@intersoft. net.au>[/color]
              wrote:[color=blue]
              >
              > [snip]
              >[color=green]
              > > I could be using the wrong terminology, what I ment is to get the
              > > content of the web page the URL pointing to....so[/color]
              >
              > Please read the FAQ (<URL:http://jibbering.com/faq/>). Your question is
              > answered there.[/color]

              Thanks for that, but I think that asi a way too complicated solution....

              If there is no simpler, I can just create a new window with the URL and read
              the content of the DOC if nothing better, but I do beleive thre should be a
              simpler solution...?

              Thanks anyway,

              Tom


              Comment

              • Berislav Lopac

                #8
                Re: How do I retrieve a URL into a variable?

                Tom Szabo wrote:[color=blue][color=green]
                >> By "retrieve a URL" do you mean of the page containing the JS?[/color]
                >
                > I could be using the wrong terminology, what I ment is to get the
                > content of the web page the URL pointing to....so
                >
                > var "url" would contain something like:
                >
                > "<html>
                > <head>
                > ....
                >
                > .....
                > /html>"
                >
                > Am I making sense? sorry if still not ....
                >
                > TIA,
                >
                > Tom[/color]

                Use XmlHttpRequest object.

                Berislav


                Comment

                • McKirahan

                  #9
                  Re: How do I retrieve a URL into a variable?

                  "Tom Szabo" <tom@intersoft. net.au> wrote in message
                  news:419b4cfd$1 @dnews.tpgi.com .au...[color=blue][color=green][color=darkred]
                  > > >> cURL = somefunction("h ttp://www.domain.com" );[/color]
                  > > ...[color=darkred]
                  > > > By "retrieve a URL" do you mean of the page containing the JS?[/color]
                  > >
                  > > I suspect the OP is actually referring to retrieving the content
                  > > of another URL (than the page itself) into a JS var as text.[/color]
                  >
                  > YES, correct, that is what I like to do...[/color]


                  Will this help? Watch for word-wrap.

                  Change the value of "onclick=XM L()" as necessary.

                  <html>
                  <head>
                  <title>XMLHTTP. htm</title>
                  <script type="text/vbscript">
                  Sub XML(strURL)
                  Dim strXML
                  strXML = strURL
                  Dim objXML
                  Set objXML = CreateObject("M icrosoft.XMLHTT P")
                  objXML.Open "GET", strURL, False
                  objXML.Send
                  If Err.Number = 0 And objXML.Status = 200 Then
                  strXML = objXML.Response Text
                  strXML = Replace(strXML, "<","&lt;")
                  strXML = Replace(strXML, ">","&gt;")
                  strXML = Replace(strXML, vbLf,"<br>")
                  End If
                  Set objXML = Nothing
                  document.write( strXML)
                  End Sub
                  </script>
                  </head>
                  <body>
                  <input type="button" value="Click Me!"
                  onclick="XML('h ttp://www.Google.com/')">
                  </body>
                  </html>


                  Comment

                  • McKirahan

                    #10
                    Re: How do I retrieve a URL into a variable?

                    "McKirahan" <News@McKirahan .com> wrote in message
                    news:ScKmd.9876 3$HA.57358@attb i_s01...[color=blue]
                    > "Tom Szabo" <tom@intersoft. net.au> wrote in message
                    > news:419b4cfd$1 @dnews.tpgi.com .au...[color=green][color=darkred]
                    > > > >> cURL = somefunction("h ttp://www.domain.com" );
                    > > > ...
                    > > > > By "retrieve a URL" do you mean of the page containing the JS?
                    > > >
                    > > > I suspect the OP is actually referring to retrieving the content
                    > > > of another URL (than the page itself) into a JS var as text.[/color]
                    > >
                    > > YES, correct, that is what I like to do...[/color]
                    >
                    >
                    > Will this help? Watch for word-wrap.
                    >
                    > Change the value of "onclick=XM L()" as necessary.[/color]

                    [snip]

                    You probably wanted the JavaScript version.

                    <html>
                    <head>
                    <title>Google.h tm</title>
                    <script type="text/javascript">
                    function XML(strURL) {
                    var objXML = new ActiveXObject(" Microsoft.XMLHT TP");
                    objXML.open("GE T",strURL,false );
                    objXML.send();
                    var strXML = objXML.response Text;
                    strXML = strXML.replace(/</g,'&lt;');
                    strXML = strXML.replace(/>/g,'&gt;');
                    strXML = strXML.replace(/\n/g,'<br>');
                    document.write( strXML)
                    }
                    </script>
                    </head>
                    <body>
                    <input type="button" value="Click Me! (js)"
                    onclick="XML('h ttp://www.Google.com/')">
                    </body>
                    </html>


                    Comment

                    • Tom Szabo

                      #11
                      Re: How do I retrieve a URL into a variable?

                      [color=blue]
                      > You probably wanted the JavaScript version.
                      >
                      > <html>
                      > <head>
                      > <title>Google.h tm</title>
                      > <script type="text/javascript">
                      > function XML(strURL) {
                      > var objXML = new ActiveXObject(" Microsoft.XMLHT TP");
                      > objXML.open("GE T",strURL,false );
                      > objXML.send();
                      > var strXML = objXML.response Text;
                      > strXML = strXML.replace(/</g,'&lt;');
                      > strXML = strXML.replace(/>/g,'&gt;');
                      > strXML = strXML.replace(/\n/g,'<br>');
                      > document.write( strXML)
                      > }
                      > </script>
                      > </head>
                      > <body>
                      > <input type="button" value="Click Me! (js)"
                      > onclick="XML('h ttp://www.Google.com/')">
                      > </body>
                      > </html>[/color]

                      Thanks, I will give it a go. Looks like this is is what I wanted,

                      Thanks again,

                      Tom


                      Comment

                      • Dr John Stockton

                        #12
                        Re: How do I retrieve a URL into a variable?

                        JRS: In article <ScKmd.98763$HA .57358@attbi_s0 1>, dated Wed, 17 Nov
                        2004 15:35:14, seen in news:comp.lang. javascript, McKirahan
                        <News@McKirahan .com> posted :[color=blue]
                        >"Tom Szabo" <tom@intersoft. net.au> wrote in message
                        >news:419b4cfd$ 1@dnews.tpgi.co m.au...[color=green][color=darkred]
                        >> > >> cURL = somefunction("h ttp://www.domain.com" );
                        >> > ...
                        >> > > By "retrieve a URL" do you mean of the page containing the JS?
                        >> >
                        >> > I suspect the OP is actually referring to retrieving the content
                        >> > of another URL (than the page itself) into a JS var as text.[/color]
                        >>
                        >> YES, correct, that is what I like to do...[/color]
                        >
                        >
                        >Will this help? Watch for word-wrap.[/color]

                        Watching for word-wrap is the author's duty. Don't be slothful.

                        [color=blue]
                        >Change the value of "onclick=XM L()" as necessary.
                        >
                        ><html>
                        ><head>
                        ><title>XMLHTTP .htm</title>
                        ><script type="text/vbscript">
                        >Sub XML(strURL)
                        > Dim strXML
                        > strXML = strURL
                        > Dim objXML
                        > Set objXML = CreateObject("M icrosoft.XMLHTT P")
                        > ...[/color]

                        Not only is this a javascript newsgroup, but it is also substantially a
                        group for web pages.

                        Therefore, since many differing OSs and browsers can be used to read Web
                        pages, a "solution" that works only with Microsoft systems is of limited
                        use, unless the OP has indicated otherwise. When a limited-use
                        "solution" is presented, a corresponding warning should be given. Yours
                        appears to be such a "solution", even in javascript.


                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
                        Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                        Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

                        Comment

                        Working...