简体   繁体   English

在jQuery UI对话框中动态加载本地HTML文件

[英]Load Local HTML Files Dynamically inside the jQuery UI Dialog

Load Local HTML Files Dynamically inside the jQuery UI Dialog 在jQuery UI对话框中动态加载本地HTML文件

Here is my code below, I'm trying to load and display the content of wtf.html in the modal. 这是下面的代码,我正在尝试加载并显示模式中wtf.html的内容。 But it doesn't show in Google Chrome 35, 36 nor IE, however, it works fine in Firefox 28 and 30.. 但它不会在Google Chrome 35、36或IE中显示,但是在Firefox 28和30中可以正常工作。

We did I do wrong? 我们做错了吗?

<div></div>

<script type="text/javascript">

$(function ()    {
    $('<div>').dialog({
        modal: true,
        open: function (){$(this).load('wtf.html');},         
        height: 400,
        width: 400,
        title: 'Dynamically Loaded Page'
    });
});

</script>

这是来自Firefox

这是从谷歌浏览器

Nothing wrong. 没有什么不对。 It is a known issue with Chrome. 这是Chrome的已知问题。 See here for details: https://code.google.com/p/chromium/issues/detail?id=40787 详情请参阅这里: https : //code.google.com/p/chromium/issues/detail?id=40787

The same must be for IE. 对于IE也必须如此。 The best way to fix this issue is to use a Development web server. 解决此问题的最佳方法是使用开发Web服务器。 For Windows I would suggest Mongoose . 对于Windows,我建议使用Mongoose It is small fast and lightweight. 它体积小,重量轻。

PS: You can go around this issue in Chrome by launching Chrome with --disable-web-security flag, but it is not encouraged. PS:您可以通过在Chrome中使用--disable-web-security标志启动Chrome来解决此问题,但不建议这样做。 Better to use a web server. 最好使用Web服务器。

I think the key is you state these are local files. 我认为关键是您要声明这些是本地文件。 Some browsers block use of ajax when file is opened from file: protocol. 当从file:协议打开file:时,某些浏览器会阻止ajax的使用。

You should be able to adjust security settings to allow for it. 您应该能够调整安全设置以允许这样做。 Alternatively install a localhost server on your computer 或者在您的计算机上安装localhost服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM