最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why won't my JS file load? - Stack Overflow

programmeradmin5浏览0评论

using this code:

<script src="<?php bloginfo('template_url'); ?>/scripts/hovermenus.js" type="text/javascript"></script>

to load this script

firebug is not showing this script as loaded, however, these scripts:

<script src="<?php bloginfo('template_url'); ?>/scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/salf_ui.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/date.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/datePicker.js" type="text/javascript"></script>

all load perfectly well. I have double, triple and quadruple checked the file is in the right directory.

using this code:

<script src="<?php bloginfo('template_url'); ?>/scripts/hovermenus.js" type="text/javascript"></script>

to load this script

firebug is not showing this script as loaded, however, these scripts:

<script src="<?php bloginfo('template_url'); ?>/scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/salf_ui.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/date.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/datePicker.js" type="text/javascript"></script>

all load perfectly well. I have double, triple and quadruple checked the file is in the right directory.

Share Improve this question edited Oct 20, 2010 at 20:59 Mild Fuzz asked Oct 20, 2010 at 20:48 Mild FuzzMild Fuzz 30.9k34 gold badges105 silver badges152 bronze badges 4
  • What does the rendered html look like? – Sean Vieira Commented Oct 20, 2010 at 20:49
  • 2 The only difference I can see if the charset attribute on the one that doesn't work. Have you tried removng that? – Ian Devlin Commented Oct 20, 2010 at 20:51
  • And when you go to <?php bloginfo('template_url'); ?>/scripts/hovermenus.js does the script show up? – Sean Vieira Commented Oct 20, 2010 at 21:19
  • anything in your Error Console? have you checked the permissions of the file? – jrn.ak Commented Oct 20, 2010 at 21:21
Add a ment  | 

7 Answers 7

Reset to default 1

Looks like the problem is with your file

Make sure the file .../scripts/hovermenus.js exists. Navigate there and copy paste the file name from there.

Could the script be in another directory? could it be hoverMenus.js or hover.menus.js.... etc.

If none of this works, try copying and renaming the file. See if you can load the renamed version. If you can't, it's something in the file.

Unrelated: You should declare your variables with var so you don't create a bunch of global variables attached to window.

You see these:
Why doesn't ASP.NET (3.5) always load an external javascript?

Firebug doesn't load JavaScript files or stop execution on breakpoints

charset isnt a valid attribute for the script tag, try removing it

EDIT

Actually it is valid, try removing it anyway :)

Make sure you've closed all your script tags above the one you're trying to load.

I had the similar problem: same file would not load on other pages(master pages)

original: 

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

fixed:    
   <script type="text/javascript" src="/Scripts/scriptMob.js"></script>

only removed dots and first slash

Additionally you can check in firebug(HTML section), expand the reference line

    (+) <script src="../../Scripts/scriptMob.js" type="text/javascript"> 

to check whether browser actually reads the js file correctly.

the error message was saying: [SqlException]: Error converting data type nvarchar to int.

Had a similar problem, shoving my head against a wall trying to figure it out. Turned out the js file had a syntax issue buried in it, something stupid that didn't show in my editor ... in this case it was a hanging 'var ' with nothing after it. As soon as I deleted that, everything was copacetic.

So my remendation if you run into this is what I did - remove all functions and add them back one by one until you find one that kills it.

Had a similar problem, cant load script /js/search_ads.js It was problem in my adblock extension After renaming to search.js problem was disappearing

发布评论

评论列表(0)

  1. 暂无评论