I begin into the worl of Javascript and I try to do something :
- Go on my webpage
- A javascript sheet on this page download another .js from another website and launch function on it or use it
The code on localhost :
index.html
<!DOCTYPE html>
<html>
<head>
<script src="test.js"></script>
<title></title>
</head>
<body>
<div id="test">
</div>
<script>
update();
setInterval(function(){document.getElementById('test').innerHTML = text()},3000);
</script>
</body>
</html>
test.js
function update(){
httpGet("http://test.localhost/blabla.js")
}
function text(){
return seeUpdate();
}
function httpGet(theUrl){
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, true );
xmlHttp.send();
return xmlHttp;
}
on test.localhost :
blabla.js
function seeUpdate(){
return "iajdiashdh";
}
So the test sheet use the blabla sheet.
How it is possible to this ? Because with my solution it doesn't work....
Thanks in advance,
Smooba
EDIT :
In fact, I found thanks to user2227904.
Here is the final version of the script :
function update(){
var imported = document.createElement('script');
imported.type = 'text/javascript';
imported.src = 'http://test.localhost/blabla.js';
document.head.appendChild(imported);
}
Thanks to everybody !
Smooba