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");
});
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");
});
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.