简体   繁体   中英

Create separate js file for inclusion

I have a html file in which currently resides all my javascript code. I want to make a separate .js file, put all the javascript code in that and include that in my .html file. I tried doing it, and also removed the opening/closing tags in the .js file and put this line in .html file -

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

However, this is not working. Any ideas on what's wrong? Thanks in advance.

---------------------EDIT-----------------------------

<html>  

<title>Process Details</title>  

<head>  
<script type="text/javascript" src="https://www.google.com/jsapi"></script>  
<script type="text/javascript" src="myfile.js">  
</script>  

<style type="text/css">  
  body { font-size: 80%; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; }  
  ul#tabs { list-style-type: none; margin: 30px 0 0 0; padding: 0 0 0.3em 0; }  
  ul#tabs li { display: inline; }  
  ul#tabs li a { color: #42454a; background-color: #dedbde; border: 1px solid #c9c3ba; border-bottom: none; padding: 0.3em; text-decoration: none; }  
  ul#tabs li a:hover { background-color: #f1f0ee; }  
  ul#tabs li a.selected { color: #000; background-color: #f1f0ee; font-weight: bold; padding: 0.7em 0.3em 0.38em 0.3em; }  
  div.tabContent { border: 1px solid #c9c3ba; padding: 0.5em; background-color: #f1f0ee; }  
  div.tabContent.hide { display: none; }  
  .heading { font-size:110%; font-family:'Century Schoolbook'; color: maroon; }  
  .data { font-size:110%; font-family:'Century Schoolbook'; color:black; }  
</style>  

</head>  

<body onload="init()">
<center>
<font face='Calibri' size='3' color='Blue'>PID : </font>
<select id='list' onchange="refreshData()">
</select>
<form>
<input type="button" id="Refresh" onclick="refreshPage()" value="Refresh Data"/>
</form>
</center>

<ul id="tabs">
<li><a href="#memory">Memory</a></li>
<li><a href="#thread">Thread</a></li>
<li><a href="#summary">Summary</a></li>
</ul>
<div class="tabContent" id="memory">
<table id="graphtab" align="center">

<tr>
<td id="heap" align="center"></td>
<td id="nonheap" align="center"></td>
</tr>
<tr>
<td id="resident" align="center"></td>
<td id="pagefaults" align="center"></td>
</tr>

</table>
</div>
<div class="tabContent" id="thread">
<table id="threadtab" align="center">

<tr>
<td id="cpuusage" align="center"></td>
<td id="count" align="center"></td>
</tr>
<tr>
<td id="threadlist" align="center"></td>
<td id="threaddets" align="center"></td>
</tr>

</table>
</div>
<div class="tabContent" id="summary">
</div>
<a href="client.html">Home Page</a>
</body>

</html>

Use http protocol instead of https . Using https throws a GET exception in Chrome but not Firefox .

And your <title> should be inside the <head> tag.

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