Getting code from a different domain into JavaScript...

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

    #1

    Getting code from a different domain into JavaScript...

    Hey hey :)

    Having a lot of problems with this. I'm helping my brother out with this art
    school web page. He has a big wish to have random images from the web shown
    in the background, and asked me to help him out.

    My idea is this: Use the CNN Top Stories RSS feed to harvest keywords, then
    use a random keyword from this harvest to search Google, get links from the
    result, look through random links here and get links to images, then load
    these images into the art web page's background.

    My first thought was to use an XmlHttpRequest object, as I've played around
    with it before and knew what it can do. Trouble is that Firefox needs some
    kind of script signing to allow retrieving data from a different domain,
    and I don't really understand how it works. Konqueror gives no warnings,
    but fails to actually load the external content, perhaps because of the
    same restriction. Add to this, IE seems to work, but pops up a warning
    dialog to the user that a script is trying to access external content which
    is unsafe. I wouldn't click okay if I saw this kind of dialog on a
    different site, so I wouldn't expect anyone to do it on this site either.

    Okay, so I looked for another way, and I read about iframes, thinking this
    would be perfect, especially considering the .links and .images properties
    already existing on a document object (making a custom lexer/parser pretty
    much superfluous). The iframes themselves work great in Konqueror, Firefox,
    and IE, loading content happily, problem is (as I've understood it) that
    iframes aren't document objects but elements, and therefore own neither
    a .links nor an .images property. Firefox console gives property not
    defined errors on both document.getEle mentById('myIfr ame').document and
    document/window.frames['myIframe'].document, anyway :(

    I can really do fine without either of these properties if I could simply
    find a way to get the external HTML code imported and script accessible so
    that I can parse it with a state machine and extract what I need.

    I've thought about a PHP solution too, but haven't looked into it thoroughly
    yet, as I understand that very few servers allow reading files from other
    domains into a local PHP script. Or is this wrong?

    I'm anxious to receive any kind of tip, so long as it's crossplatform
    compatible and not based on Java or something else (Flash etc.) that would
    require the visiting browser to have an add-on installed. The site should
    work on Safari, IE (Mac & PC), Konqueror, and Firefox. I only have the rest
    of the day to get this working (approx. 10 hours) ;)

    Thanks in advance,
    Daniel :)

    --
    Why do cats jump out of windows? Because there's love out there!
  • alex bazan

    #2
    Re: Getting code from a different domain into JavaScript...

    En/na DanielEKFA ha escrit:[color=blue]
    >
    > I've thought about a PHP solution too, but haven't looked into it thoroughly
    > yet, as I understand that very few servers allow reading files from other
    > domains into a local PHP script. Or is this wrong?[/color]

    i think that would be the best solution, and it would avoid getting into
    the security limitations of the browser.

    look into the filesystem functions
    (http://www.php.net/manual/en/ref.filesystem.php)... functions like
    file_get_conten ts() can get an url as an argument. so you can open any
    external url and dump its contents into a variable for parsing.

    you can also use the DOMDocument classes to parse the xml from feeds.

    Comment

    • Alan Little

      #3
      Re: Getting code from a different domain into JavaScript...

      Carved in mystic runes upon the very living rock, the last words of
      DanielEKFA of comp.lang.javas cript make plain:
      [color=blue]
      > I've thought about a PHP solution too, but haven't looked into it
      > thoroughly yet, as I understand that very few servers allow reading
      > files from other domains into a local PHP script. Or is this wrong?[/color]

      You do not need to have allow_url_fopen set in your PHP installation in
      order to retrieve remote content; you can simply perform HTTP operations.
      There is a function in HoloLib that will allow you to do a GET.

      ftp://ftp.holotech.net/hololib.zip

      --
      Alan Little
      Phorm PHP Form Processor

      Comment

      • DanielEKFA

        #4
        Re: Getting code from a different domain into JavaScript...

        alex bazan wrote:
        [color=blue]
        > En/na DanielEKFA ha escrit:[color=green]
        >>
        >> I've thought about a PHP solution too, but haven't looked into it
        >> thoroughly yet, as I understand that very few servers allow reading files
        >> from other domains into a local PHP script. Or is this wrong?[/color]
        >
        > i think that would be the best solution, and it would avoid getting into
        > the security limitations of the browser.
        >[/color]

        That's where I'm going now, too :) Gotten pretty sick of all that security
        stuff, although I see why it's necessary ;)
        [color=blue]
        > look into the filesystem functions
        > (http://www.php.net/manual/en/ref.filesystem.php)... functions like
        > file_get_conten ts() can get an url as an argument. so you can open any
        > external url and dump its contents into a variable for parsing.
        >
        > you can also use the DOMDocument classes to parse the xml from feeds.[/color]

        Thanks, I was about to browse the php.net docs, to check out retrieval
        methods, your tips will come in handy.

        Cheers,
        Daniel :)

        --
        Why do cats jump out of windows? Because there's love out there!

        Comment

        • DanielEKFA

          #5
          Re: Getting code from a different domain into JavaScript...

          Alan Little wrote:
          [color=blue]
          > Carved in mystic runes upon the very living rock, the last words of
          > DanielEKFA of comp.lang.javas cript make plain:
          >[color=green]
          >> I've thought about a PHP solution too, but haven't looked into it
          >> thoroughly yet, as I understand that very few servers allow reading
          >> files from other domains into a local PHP script. Or is this wrong?[/color]
          >
          > You do not need to have allow_url_fopen set in your PHP installation in
          > order to retrieve remote content; you can simply perform HTTP operations.
          > There is a function in HoloLib that will allow you to do a GET.
          >
          > ftp://ftp.holotech.net/hololib.zip
          >[/color]

          Very cool, thank you! As it appears, that library also sports a nifty HTML
          parser, perfect! :D

          Cheers,
          Daniel :)

          --
          Why do cats jump out of windows? Because there's love out there!

          Comment

          Working...