Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

html - Dynamically reload local Javascript source / json data

What are the possible cross browser (at least Firefox & Chrome) methods to dynamically reload a local Javascript file that is referenced by a locally loaded html file?

Background:

A local html page is being used to render some data that is formatted and displayed by two referenced Javascript files. One file contains the Javascript code, and the other file contains JSON data.

This JSON data is updated on disk by another program, and it would be nice to have the UI automatically incorporate these updates without manually reloading the page (or opening a new page).

In Firefox, I believe the issue could be resolved using AJAX to load the html, but in Chrome this will not work due to the same origin policy failures (I unfortunately cannot necessarily rely on --disable-web-security to mitigate this since all prior instances of Chrome must be closed for that to work).

The only solution I see is to run a local web server, but I am hoping for something simpler and less invasive (Perhaps loading the Javascript in an IFrame and reloading the IFrame, although I imagine this would be prevented by browser security).

Anyone have any recommendations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your app starts up Chrome then you can include the --allow-file-access-from-files flag in the start command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...