Hi, I have a problem, say that I have a lot of diffrent websites, and that those are on diffrent webservers, now also say that I want one specific objekt on all those websites, is it possible to write a javascript that gets that object from another webserver?
function getElementFromAnotherSite(){
/*Download www.example.com/images/example.gif
*Put it in the folder ../images/example.gif on current webserver
*document.getElementById('id_where_i_want_to_display_the_picture').background-image: url(../images/example.gif);
*/
}
I am gonna move files around alot between diffrent servers, so no file are going to be static on a webserver, thats why I want to download it on the current webserver using the file.
Is this possible in javascript? Or can this be achieved in another language?
Hi,
you can initiate action on server, and script that action to download list of files and it can return it to you with coma separated values so you can manipulate them
but in order to change background image of element you can do it like this
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://tdsoft.se/hej.txt",true);
xmlhttp.send();
/*Here I want to store this file on another server, for example
*http://hulenet.se/data/hej.txt" /*Assume that I have write access to this server*/
*/
}
</script>
</head>
<body>
<div id="myDiv"><h2>Want to download hej.txt</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
the above is to show text inside an element with id “mydiv”, if I would like to change the background, for example change the background-image to this picture “http://images.povcomp.com/entries/images/480/161_main.jpg”, what is the syntax for this?
JavaScript is client side, and this JavaScript can be executed only on client computer, not on server. But JavaScript can initiate process on server by creating request to it.
For example AJAX. You call it, then server side app download file to it and return data about file trough response.
I simply want a script that can move around files between my webservers, depending on what webb url that your’e on. I know that this can’t be done when it comes to server-local client, but can this be done between server-server?