动态地重新加载本地Javascript源/ json数据 [英] Dynamically reload local Javascript source / json data

查看:105
本文介绍了动态地重新加载本地Javascript源/ json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是可能的跨浏览器(至少Firefox和Chrome)方法来动态地重新加载本地加载的html文件引用的本地Javascript文件?



背景:

本地html页面被用来渲染一些数据,这些数据被两个引用的Javascript文件格式化和显示。一个文件包含Javascript代码,另一个文件包含JSON数据。



这个JSON数据由另一个程序在磁盘上进行更新,并且很高兴拥有UI自动合并这些更新,而无需手动重新加载页面(或打开新页面)。



在Firefox中,我相信问题可以通过AJAX加载html来解决,但在Chrome浏览器中,由于相同的原始策略失败,我无法工作(不幸的是,我不能一定依靠--disable-web-security来缓解这种情况,因为之前所有的Chrome浏览器必须关闭才能正常工作)。

b
$ b

我看到的唯一解决方案是运行一个本地web服务器,但我希望更简单一些,但侵入性更小(也许将Javascript加载到IFrame中并重新加载IFrame,但我想象得到会被浏览器安全阻止)。



任何人有任何建议吗?

解决方案

如果您的应用程序启动了C hrome,那么你可以在启动命令中加入 - 允许文件访问从文件标志。


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?

解决方案

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

这篇关于动态地重新加载本地Javascript源/ json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆