简体   繁体   English

如何在浏览器中运行.html文件?

[英]How to run the .html file in browser?

I have just wrote a javascript file which I ran the via intelliJ using a few different browsers eg Google Chrome. 我刚刚编写了一个javascript文件,我使用一些不同的浏览器(例如Google Chrome)通过intelliJ运行了该文件。 This works fine as it runs locally eg http://localhost : // . 由于它在本地运行,例如http:// localhost// ,因此效果很好。

However I want to be able to send it to someone so they just click on the .html file (packaged in correct folder) and it appears on their browser. 但是,我希望能够将其发送给某人,以便他们只需单击.html文件(包装在正确的文件夹中),它就会出现在他们的浏览器中。 Is there anyway I can do this? 反正我能做到这一点吗? Right now the url points locally eg file:///Users/**/project/file.html. 现在,URL指向本地,例如file:///Users/**/project/file.html。

Use a relative path. 使用相对路径。 If your HTML file is in the same folder as the JS file, this means simply including it like so: 如果您的HTML文件与JS文件位于同一文件夹中,则意味着像这样简单地包含它:

<script src="jsfile.js"></script>

If it's in a subdirectory, include all the folders necessary to get there: 如果在子目录中,请包括到达该子目录所需的所有文件夹:

<script src="subdirectory1/subdirectory2/jsfile.js"></script>

If it's up a directory, use the .. path: 如果在目录中,请使用..路径:

<script src="../anotherfolder/jsfile.js"></script>

Or just include it in the HTML page itself: 或者只是将其包含在HTML页面本身中:

<script>
  // your code here
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM