Make a url connection?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nicholas4@gmail.com

    Make a url connection?

    I'm trying to make a web page where a form lets you enter a url address
    in a field and upon clicking the submit button, the text of the source
    code of the page is displayed below the form. I know it'll have to
    make a url connection in javascript but I don't how to do this. Please
    help.

  • Martin Honnen

    #2
    Re: Make a url connection?



    nicholas4@gmail .com wrote:
    [color=blue]
    > I'm trying to make a web page where a form lets you enter a url address
    > in a field and upon clicking the submit button, the text of the source
    > code of the page is displayed below the form. I know it'll have to
    > make a url connection in javascript but I don't how to do this.[/color]

    The usual context here is scripting HTML pages loaded via HTTP and there
    while some browsers allow you to make a HTTP connection those
    connections are restricted to the server the HTML page has been loaded from.
    As for fetching the source of a text file from the server see the FAQ

    and


    --

    Martin Honnen

    Comment

    • Grant Wagner

      #3
      Re: Make a url connection?

      <nicholas4@gmai l.com> wrote in message
      news:1103302993 .215393.95140@z 14g2000cwz.goog legroups.com...[color=blue]
      > I'm trying to make a web page where a form lets you enter a url[/color]
      address[color=blue]
      > in a field and upon clicking the submit button, the text of the source
      > code of the page is displayed below the form. I know it'll have to
      > make a url connection in javascript but I don't how to do this.[/color]
      Please[color=blue]
      > help.[/color]

      You won't be able to use the XML HTTP Request object <url:
      http://jibbering.com/2002/4/httprequest.html /> to do what you want
      because it has no ability to retrieve content from a site that is not
      the one it was loaded from.

      The closest you can come is something like:

      <form name="myForm">
      <input type="text" name="theUrl"
      value="http://www.yahoo.com">
      <input type="button" name="myButton"
      value="Retrieve source"
      onclick="myFunc tion(this.form. elements['theUrl']);">
      </form>
      <iframe name="myIframe" ></iframe>
      <script type="text/javascript">
      function myFunction(url) {
      var s = url.value;

      if (window.frames && window.frames['myIframe']) {
      window.frames['myIframe'].location.href = 'view-source:' + s;
      }
      }
      </script>

      But it opens the source in IE's default source viewer (not the iframe)
      and doesn't work in Opera 7.54 at all.

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq


      Comment

      • rubikzube*

        #4
        Re: Make a url connection?

        You could try to load the page into an iFrame then use the innerHTML
        property to view the source. The end result should look something like
        << document.frames["iframenamehere "].document.inner HTML >>. Might not
        work due to security restrictions, though

        Comment

        Working...