473,395 Members | 1,456 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 an external content with javascript.

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.
Jul 23 '05 #1
7 10886
In article <cd**********@lacerta.tiscalinet.it>,
va****************@quipo.itttttt enlightened us with...
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.


Not in plain, ordinary, cross-browser, client-side javascript for
general internet use.

If your situation is different than the above, let us know.
ActiveX, COM, applets, and other ways exist to do this, but none of them
work on every browser for every platform and thus are not suitable for
general internet use.

Server-side scripting could do this with no problems.

--
--
~kaeli~
A lot of money is tainted - It taint yours and it taint mine.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Lorenzo Vaina wrote:
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.


No, client-side Javascript can neither read nor write files on a Web server
served from another domain.

Yes, client-side Javascript can be made to "read" files from a Web server
served from the same domain that the Javascript was served from, but it can
not permanently write any changes back to the server without help from
executable code running on the server (ASP, C, JSP, Perl, PHP, etc).

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
> 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.


In general, no. In the context of a particular browser, yes with
caveats. I wrote about two ways with Internet Explorer 5+ in my
journal [1]. With MSIE 5+, you can also use the download DHTML
behavior (although there are memory leaks using it sometimes).
Mozilla's JavaScript engine also mimics some parts of IE's interface
with the XMLHttpRequest object [3].

Hope that helps,

--
Jimmy Cerra

[1] http://slashdot.org/~Quantum%20Jim/journal/72680/

[2] http://msdn.microsoft.com/workshop/a...s/download.asp

[3] http://jibbering.com/2002/4/httprequest.html
Jul 23 '05 #4
> No, client-side Javascript can neither read nor write files on a Web
server
served from another domain.
Ok.
Yes, client-side Javascript can be made to "read" files from a Web server
served from the same domain that the Javascript was served from,
How please, if you are so patient?
but it can
not permanently write any changes back to the server without help from
executable code running on the server (ASP, C, JSP, Perl, PHP, etc).


Obviously.

Thanks, regards.
Jul 23 '05 #5
Lorenzo Vaina wrote:
No, client-side Javascript can neither read nor write files on a Web

server
served from another domain.


Ok.
Yes, client-side Javascript can be made to "read" files from a Web server
served from the same domain that the Javascript was served from,


How please, if you are so patient?


Using the XML HTTP Request object available in IE or Gecko-based browsers.
Information on this is available at:
<url: http://jibbering.com/2002/4/httprequest.html />

Or you can retrieve the content from the server into a hidden <iframe> and read
it from there:

<body onload="test();">
<iframe id="contentId" name="contentName" style="display:none;"
src="test.txt"></iframe>
<script type="text/javascript">
function test() {
var iframe;
if (document.getElementById && !document.frames) {
iframe = document.getElementById('contentId');
if (iframe &&
iframe.contentDocument &&
iframe.contentDocument.body &&
typeof iframe.contentDocument.body.innerHTML == 'string') {

alert('using getElementById: ' +
iframe.contentDocument.body.innerHTML);
}
} else if (document.frames) {
iframe = document.frames['contentName'];
if (iframe &&
iframe.document &&
iframe.document.body &&
typeof iframe.document.body.innerHTML == 'string') {

alert('using document.frames: ' + iframe.document.body.innerHTML);
}
} else {
alert('Browser does not support examining the content of an iframe');
}
}
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Thanks for your reply.
Or you can retrieve the content from the server into a hidden <iframe> and read it from there:


This metod appears more compatible; pharaps i could retrieve and read the
url content in a window too; i will study how make the text not readeable by
humans.
Jul 23 '05 #7
Thanks for your reply.
Jul 23 '05 #8

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

Similar topics

2
by: sdvoranchik | last post by:
We have an application that contains links that run javascripts to create pages in a separate frame. When these links open an external site, it causes the javascripts to no longer function. When...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
4
by: DanielEKFA | last post by:
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...
6
by: john.lum | last post by:
I am using document.write in an external javascript file to display some content, but I've found that I can't rely on that content being displayed in the location I expect. Here's a very simple...
4
by: dennise9 | last post by:
My exeternal JS works fine when the call is placed in the page head or body. But if I call the same javascript from a (clicked) text link on the page, the script throws a JS error when it...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
38
by: Neo Geshel | last post by:
I am seeking a method to load one JS file directly into another, *without* having to dynamically write <scripttags. Is there any method whereby I can call only one external JS file using a ...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
3
by: RICHARD BROMBERG | last post by:
I have a simple program to test using an external .js file. This external file contains some functions that I need to call from several html programs. The program as written below works fine. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.