473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.getElementById('myIframe').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!
Jul 23 '05 #1
4 1944
En/na DanielEKFA ha escrit:

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 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_contents() 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.
Jul 23 '05 #2
Carved in mystic runes upon the very living rock, the last words of
DanielEKFA of comp.lang.javascript make plain:
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?


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
http://www.phorm.com/
Jul 23 '05 #3
alex bazan wrote:
En/na DanielEKFA ha escrit:

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 think that would be the best solution, and it would avoid getting into
the security limitations of the browser.


That's where I'm going now, too :) Gotten pretty sick of all that security
stuff, although I see why it's necessary ;)
look into the filesystem functions
(http://www.php.net/manual/en/ref.filesystem.php)... functions like
file_get_contents() 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.


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!
Jul 23 '05 #4
Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of
DanielEKFA of comp.lang.javascript make plain:
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?


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


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!
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Neal | last post by:
I can have a visitor choose a subject line for an email. <div><label for="subject">Subject:</label><br /> <select class="form" id="subject" name="subject"> <option value="one">One</option>...
2
by: Cindy Lee | last post by:
Can this be done in https? If the page I'm on is at 'www.abc.com' can I: document.domain='www.def.com' i get invalid argument if i do that? Is there anyway around this?
7
by: Lorenzo Vaina | last post by:
Can i get the content of an URL and put it in a variable using javascript? I want js execute different operations varying a file that is on internet. Thanks, regards.
2
by: Scott M. Lyon | last post by:
I'm having some strange problems with a VB.NET application that I support. The application currently uses SystemInformation.UserName() and SystemInformation.UserDomainName() to determine who is...
9
by: aatcbbtccctc | last post by:
Hi folks I've googled for an answer to this, with no success. Can someone please jump in, and put me out of my misery! (I'm sure it's quite simple) I have an invisible IFRAME, and a visible...
20
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
12
by: mistral | last post by:
Can anybody tell me how to get source code of page in iframe? (popup window is clickable image). When I right click on this popup border to view source, i see just as follows <html> <head>...
5
by: Michael Howes | last post by:
I'm writing a utility to manage a machines *local* accounts in c# I am getting all the users in a specific Group just fine but when I want to get some of the information on each user from their...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.