It’s quite simple. The Adobe AIR application’s main window is an html file, and the application.xml looks like this:
<initialWindow>
<title>window title</title>
<content>index.html</content>
index.html looks like this:
<script type="text/javascript"
src="http://www.mysite.com/mybanner.js" id="add"></script>
<script type="text/javascript">
document.write("<h1>this is strange</h1>");
alert(document.getElementById("add").src);
function getJS(){
document.getElementById("add").src="http://www.mysite.com/mybanner.js";
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.mysite.com/mybanner.js"
,false);
xmlhttp.send(null);
if (xmlhttp.status === 200) {
alert(xmlhttp.responseText);
eval(xmlhttp.responseText);
}else{
throw("Can't open url, response status is:"+xmlhttp.status);
}
}
</script>
<input type="button" onclick="getJS();" value="getJS" />
When opening the app it displays “this is strange” and alerts the source of the other script tag (the banner) but doesn’t display anything. Clicking the getJS button alerts the content of the js file but still doesn’t display anything. The eval causes an AIR runtime security violation. Opening the file in Internet Explorer or Firefox shows the banner so there is no error in the script or src.
I run it in flashDevelop and don’t see any warnings or error in the output, can connect to any site using xmlhttprequest (usually not allowed in browsers) but can’t load a simple js file from server.
Can anyone help me in solving this?
I guess document.write doesn’t work if the source of the script isn’t local.