简体   繁体   中英

How can I remove html tags from a javascript file on a webpage?

I'm making a game in html/javascript. I kept the html and the javascript in 2 different files, and locally the program works fine, so I attempt to place the files on my website as two webpages http://wdixon.droppages.com/coffee_brewers_v2 is the html and http://wdixon.droppages.com/coffee_brewers_v2_js is the javascript file (created with sublime text 2 and saved as a .js) the html references the javascript file with the following tag

<script src="/coffee_brewers_v2_js" type="text/javascript"></script>

but unlike my local tests, the online version doesn't receive the javascript file.

I believe this is because the javascript file is being interpreted as html when you view the source of the javascript page you can see html that I did not write.

What's going on? How can I fix this? (other than putting all the javascript code in the html file)

EDIT: I have renamed the javascript file coffee_brewers_v2.js

and change the html tag in the html file to:

<script src="/coffee_brewers_v2.js" type="text/javascript"></script>

The problem persists

EDIT 2: I'm now noticing even the .html has paragraph tags that I didn't put there. I'm using droppages(dot)com (dont have the reputation to post a 3rd link in one question) via dropbox to host the webpages could they be the problem?

EDIT FINAL: Droppages was forcibly interpreting every file as an html. I figured out how to stop that from their website. And it all works perfectly. You can play my awful game as a reward for sticking it out with me (it works!)

The response from the server for the file coffee_brewers_v2_js is

  HTTP/1.1 200 OK
  Cache-Control: private
  Content-Type: text/html; charset=utf-8
  Expires: Fri, 22 Jan 2016 23:49:43 GMT
  Last-Modified: Fri, 22 Jan 2016 19:06:44 GMT
  Server: Microsoft-IIS/7.0
  Date: Fri, 22 Jan 2016 23:50:43 GMT
  Content-Length: 6108
Length: 6108 (6.0K) [text/html]

which supports you assumption that is gets send as HTML. You may try to rename the JavaScript file to coffee_brewers_v2.js to make Microsoft's IIS happy. Most Webservers handle filetypes by the endings if not told otherwise.

我不确定这是否是故意的,但是您错过了代码中的.js扩展名。

<script src="/coffee_brewers_v2_js.js" type="text/javascript"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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