[英]How do I open a local file from a button press in JavaScript/HTML?
I am very new to JavaScript and HTML. 我对JavaScript和HTML非常陌生。 I created an example where im trying to open a local file called, "TNTplayer.html" in a JavaScript function via a button press.
我创建了一个示例,我尝试通过按下按钮在JavaScript函数中打开名为“ TNTplayer.html”的本地文件。 However, I don't know the line of code that will do that.
但是,我不知道能做到这一点的代码行。
function myFunction() { document.location.href=document.location.href.splitOnLast('/')[0]+"/TNTplayer.html"; }
<p>Click the button.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p>
Have a look at this article: http://researchhubs.com/post/computing/javascript/open-a-local-file-with-javascript.html 看看这篇文章: http : //researchhubs.com/post/computing/javascript/open-a-local-file-with-javascript.html
In general, if your HTML/JS is being served as a website, you will not have "true" access to your filesystem (which is a necessary security measure), besides the ways mentioned in the article above. 通常,如果将HTML / JS用作网站,则除了上面文章中提到的方法之外,您将没有对文件系统的“真实”访问(这是必要的安全措施)。
However, if you are serving it as a standalone client application, which is possible using frameworks such as Nodejs and others, there are framework specific ways of accessing the filesystem. 但是,如果将其作为独立的客户端应用程序使用(可以使用诸如Node.js和其他框架之类的框架来实现),则可以使用特定于框架的访问文件系统的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.