I have a javascript file named “a.js” located in host a.
The code in a.js is as below:
function sayHello() {
alert("Hello, world");
}
I have a html file named b.html located in host b, in which there are code like below:
<html>
<head>
<script type="text/javascript" src="http://a/js/a.js" />
<script type="text/javascript">
sayHello();
</script>
</head>
<body>
</body>
</html>
When I key in the url “http://b/b.html” in my browsers (I have tested in IE8, Chrome), my browsers don’t pop the alert window. Did I miss something configuration ?
How should I do so that my b.html can include a javascript file which is located in another host and the functions in the javascript file can be executed just like we include Google’s javascript API files ?
Thank you for your help.
You’re having this problem because the
<script>tag is not self-closing (unless you’re serving your file with a XML content-type). As Dr.Dredel said, in this case it’s not related to any kind of security restriction. Change your markup to:Further reference: Why don’t self-closing script tags work?