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.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!