1
votes

UPDATE

I got rid of the errors but the JS still dosen't work.

In the MasterPage head section I have this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/js/script.js"></script>
<script src="/js/jquery.sticky.js"></script>
<script>
    $(document).ready(function(){
    $("#container_menu").sticky({ topSpacing: 0 });
    });
</script>

When inspecting the page in the browser I get these warnings and errors:

jquery.min.js:2 jQuery.Deferred exception: Cannot read property 'left' of undefined TypeError: Cannot read property 'left' of undefined at HTMLDocument. (http://localhost:64093/js/script.js:2:31) at l (http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29375) at c (http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29677) undefined w.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 jQuery.Deferred exception: $(...).sticky is not a function TypeError: $(...).sticky is not a function at HTMLDocument. (http://localhost:64093/:17:30) at l (http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29375) at c (http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29677) undefined w.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 Uncaught TypeError: Cannot read property 'left' of undefined at HTMLDocument. (script.js:2) at l (jquery.min.js:2) at c (jquery.min.js:2) jquery.min.js:2 Uncaught TypeError: $(...).sticky is not a function at HTMLDocument. ((index):17) at l (jquery.min.js:2)

ORIGINAL POST

*I'm trying to link a js file from /js/file.js in the head section of a master page. I tried everything I found on the internet with no luck. Not sure what I'm doing wrong.

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/>
<script type="text/javascript" src="~/js/jquery.sticky.js" />

The error I got is having something to do with the JS code in my opinon. Here's what I got:

 BC30035: Syntax error.
          Line 1:  (function (factory) {
          Line 2:      if (typeof define === 'function' && define.amd) {
          Line 3:          // AMD. Register as an anonymous module.
1
You shouldn't have runat="server" in there.Andrew Morton
try to load without type="" -> <script src="~/js/jquery.sticky.js" /> and maybe you could post some info about the error. and maybe use a newer jquery version: ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.jsG43beli
where in your tree is your masterpage and where is the js file excactly? Could be something wrong with the pathG43beli
try to add <base href="/"> to the beginning of your headG43beli
In your browser, open the developer tools (F12) and find the network tab. Clear it if there is anything shown. In the browser window, refresh the page (F5). Go back to the network tab and look for where it loads jquery.sticky.js - if it has an HTTP response code of 200 or 304 then it was loaded into the browser, otherwise you need to find out why it was not delivered to the browser.Andrew Morton

1 Answers

1
votes

Here's a trick: Open the master page and the Solution Explorer. Drag the .js file from Solution Explorer into the head of the master page and try again.