helloxielan 2015-06-18 14:52 采纳率: 0%
浏览 46

无法加载ajax

I can't display my .txt file in html page (local), with .load. File is in the same folder with .js.

$(function(){  
    $("#div1").load("text.txt");  
}); 
  • 写回答

1条回答 默认 最新

  • weixin_33709609 2015-06-18 16:24
    关注

    Last time I checked, opening local files with local HTML will work in IE but not Chrome, Firefox, etc. due to security reasons.

    If you're comfortable with HTML and javascript and want to run things locally and manipulate local files, have a look at HTML Applications or .hta. It's pretty neat.

    Here is Microsoft's documentation and here is an example with Javascript.

    To avoid the Windows system ActiveX warnings, your program should run under an .hta envelope, ie, as an application (like an .exe file).

    The following code opens your application under the .hta "umbrella", in a window of your sizing (in the example: 1030 x 95 pix) centered in the lateral direction and low on the screen. It does not allow scrolling. Make a text file and save it under YourChoiceOfName.hta

    <HTML>
    <HEAD>
    <script language="javascript" type="text/javascript">
      function Set(){   // this limits the size of the window opened and positions it
        var l=(screen.width/2 - 515); // centre - half the window width
        var t=(screen.height-130); // where you want it vertically
        self.moveTo(l,t);
        self.resizeTo('1030','95'); // as you can see, this example opens a longish but squat window, near the task-bar
      }
    </script>
    <TITLE>BlahBlah-The Progam</TITLE>
    <HTA:APPLICATION ID="BlahBlah-App"
        BORDER="thin"
        INNERBORDER="no"
        SCROLL="no" 
        SCROLLFLAT="no"
        CAPTION="yes"    
        MAXIMIZEBUTTON="no"
        SHOWINTASKBAR="yes"
        SINGLEINSTANCE="yes"
        SYSMENU="yes"
        NAVIGABLE="yes"
        ICON="images/favicon.ico"
        WINDOWSTATE="normal">
    <STYLE> body {margin:0} </STYLE>
    </HEAD>
    <BODY onload="Set()" >
    <IFRAME src="blahblah.htm" application=yes width=1030 // width is that of your window
    height=95 marginwidth=0 marginheight=0   /// height is that of your window
    frameborder=0>Iframes not supported</IFRAME>
    </BODY>
    </HTML>
    

    Note that you don't have to use an iframe as he does, you can put your HTML right in the HTA file.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。