I think I've figured it out.
All I really needed to do was add a callback into my <script>
tag. Final code:
I have an element named next... So, in the $("#next").click()
function I have the following code. This only gets executed if they click "next".
//remove old dynamically written script tag-
var old = document.getElementById('uploadScript');
if (old != null) {
old.parentNode.removeChild(old);
delete old;
}
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.id = 'uploadScript';
script.type = 'text/javascript';
script.src = 'test/' + scope_dir + '/js/list.js';
script.onload = refresh_page;
head.appendChild(script);
function refresh_page(){
//perform action with data loaded from the .js file.
}
This seems to work, and allows Chrome to dynamically load .js files on the local file system while circumventing the access-control-allow-origin policy I ran into while trying to use jQuery functions.
Best Answer
Close chrome (or chromium) and restart with the
--disable-web-security
argument. I just tested this and verified that I can access the contents of an iframe with src="http://google.com" embedded in a page served from "localhost" (tested under chromium 5 / ubuntu). For me the exact command was:Note : Kill all chrome instances before running command
The browser will warn you that "you are using an unsupported command line" when it first opens, which you can ignore.
From the chromium source:
Before Chrome 48, you could just use: