我使用javascript来加载一些html页面在另一个html页面。它的工作正常在Mozilla Firefox,但不工作在谷歌Chrome和IE10 [英] I am using javascript to load some html page in another html page. Its working fine in Mozilla Firefox but not working in Google Chrome and IE10

查看:107
本文介绍了我使用javascript来加载一些html页面在另一个html页面。它的工作正常在Mozilla Firefox,但不工作在谷歌Chrome和IE10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为下拉菜单编写代码,并希望在其他html文件中插入该代码。
DropDown菜单代码。



http://jsfiddle.net/techspartan/49Bpb /



要将上述HTML代码插入其他HTML文件,我使用的代码如下:

 < html> 
< head>
< script src =jquery-2.0.3.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
$('#topdiv')。load('index.html');
});
< / script>
< / head>

< body>
< div id =topdiv>
< / div>
< / body>
< / html>

基本上我想在一个位置声明我的DropDownMenu代码,如果我在菜单代码我不需要编辑每个具有DropDown的HTML文件。



上述代码在Firefox中工作,但在Chrome和IE-10中没有显示。 p>

解决方案

您是否在本地机器上工作,没有任何网络服务器? Chrome不允许通过AJAX从您的文件系统加载文件(请参阅 bugreport )。

您可以使用XAMPP或类似的东西通过本地网络服务器提供您的文件。



如果你是在Windows上,XAMPP可能是最简单的方式来获取本地网络服务器并运行: http://www.apachefriends.org/en/xampp.html



在Mac上,您还可以使用MAMP http ://www.mamp.info/en/index.html



您也可以强制Chrome在Windows上允许本地文件访问(如果您启动它) - allow-file-access-from-files ,更多信息在这个stackoverflow问题


I wrote code for dropdown Menu and want to insert that code in other html files. DropDown Menu code.

http://jsfiddle.net/techspartan/49Bpb/

For inserting the above HTML code into other HTML files I am using this code:

  <html>
     <head>
       <script src="jquery-2.0.3.js"></script>
       <script type="text/javascript">
         $(document).ready(function(){
           $('#topdiv').load('index.html');
         });
       </script>
     </head>

    <body>
     <div id="topdiv">
     </div>
    </body>
 </html>

Basically I want to declare my DropDownMenu code at one location so that if I make changes in menu code than I don't have to edit every HTML file that has the DropDown.

The above code is working in Firefox but nothing is shown in Chrome and IE-10.

解决方案

Are you working locally on your machine, without any webserver? Chrome does not allow loading files via AJAX from your file system (see bugreport).

You may use XAMPP or something similar to serve your files via a local webserver.

If you are on Windows, XAMPP is probably the easiest way to get your local webserver up and running: http://www.apachefriends.org/en/xampp.html

On Mac, you may also use MAMP http://www.mamp.info/en/index.html

You may also force Chrome to allow local file access on Windows if you are starting it with --allow-file-access-from-files, more information in this stackoverflow question

这篇关于我使用javascript来加载一些html页面在另一个html页面。它的工作正常在Mozilla Firefox,但不工作在谷歌Chrome和IE10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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