Actually, it is impossible to download any content from one site to
another one within JavaScript. This technology called AJaX, but it
only allows you to download data from only your site.
For example:
You can insert
<script type="text/javascript" src="http://mydomain.com/script.js"></script>
on page http://mydomain.com/page.html and it will successfully
download data, but if you insert:
<script type="text/javascript" src="http://mydomain.com/script.js"></script>
on page http://someotherdomain.com/page.html, it will not work. It
will say "Access denied".
If you want to solve this problem you should not download data from
website in your javascript, but you should print it.
For example, you may have a javascript code like this:
var p = document.body.appendChild(document.createElement('p'))
p.appendChild(document.createTextNode('It works!'));
and it will work, wherever you place it on
http://mydomain.com/page.html or http://anythingelse.com/page.html
But, I guess you want javascript to load dynamic data, don't you?
In this case you should use server side scripts like perl, php or anything else.
For example, if you create a php script http://mydomain.com/script.php like this:
<?
$data = getSomeData();
?>
var p = document.body.appendChild(document.createElement('p'))
p.appendChild(document.createTextNode('<?=$data?>'));
and call it like:
<script type="text/javascript" src="http://mydomain.com/script.php"></script>
wherever from http://mydomain.com/page.html or http://anythingelse.com/page.html,
it will work and reproduce and html code like this:
<p>$data</p>
$data is a PHP variable, containing any text. You can write data from
database or a file in this variable, and javascript will show it. |