I have a custom master page and I am trying to include some jquery files but when the page loads the browser is not picking up the jquery files at all. It does not load them and there are no errors displayed.
Here is the whole HEAD section of the master page, assistance is appreciated.
<head runat=”server”>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>
<meta http-equiv=”Expires” content=”0″/>
<meta http-equiv=”X-UA-Compatible” content=”IE=8″/><!– robots –>
<SharePoint:RobotsMetaTag runat=”server”/><!– page title – overridden by asp:content on pages or page layouts –>
<title runat=”server”><asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server”>SiteName</asp:ContentPlaceHolder></title><!– favicon –>
<SharePoint:SPShortcutIcon runat=”server” IconUrl=”/images/favicon.ico”/><!– all OOTB css –>
<SharePoint:CssLink runat=”server” Version=”4″/>
<SharePoint:Theme runat=”server”/><!– page manager interacts with script and the sharepoint object model –>
<SharePoint:SPPageManager runat=”server”/><!– unified logging service –>
<SharePoint:ULSClientConfig runat=”server”/><!– identifies to scripting elements that this is a v4 master page. required for scrolling? –>
<script type=”text/javascript”>
var _fV4UI = true;
</script><!– load SharePoint javascript –>
<SharePoint:ScriptLink language=”javascript” Defer=”true” runat=”server”/><style type=”text/css”>
/* fix scrolling on list pages */
#s4-bodyContainer {
position: relative;
}/* hide body scrolling (SharePoint will handle) */
body {
height:100%;
overflow:hidden;
width:100%;
}/* popout breadcrumb menu needs background color for firefox */
.s4-breadcrumb-menu {
background:#F2F2F2;
}/* if you want to change the left nav width, change this and the margin-left in .s4-ca */
body #s4-leftpanel {
/* width:155px; */
}/* body area normally has a white background */
.s4-ca {
background:transparent none repeat scroll 0 0;
/* margin-left:155px; */
}
</style><!– link to our custom css –>
<SharePoint:CssRegistration name=”<% $SPUrl:http://qahome/Style Library/Site.css %>” After=”corev4.css” runat=”server”/><!–javascript to override the active-x message in ie
// See http://blog.drisgill.com/2010/02/removing-name-activex-control-warning.html for more info
// Remove if the IM pressence icons are needed in SharePoint
–>
<script type=”text/javascript”>
function ProcessImn(){}
function ProcessImnMarkers(){}
</script><!– additional header delegate control –>
<SharePoint:DelegateControl runat=”server” ControlId=”AdditionalPageHead” AllowMultipleControls=”true”/><!– additional header placeholder – overridden by asp:content on pages or page layouts –>
<asp:ContentPlaceHolder id=”PlaceHolderAdditionalPageHead” runat=”server”>
</asp:ContentPlaceHolder>
<!– microsoft says these should always be inside the head tag. –>
<asp:ContentPlaceHolder id=”PlaceHolderBodyAreaClass” runat =”server”/>
<asp:ContentPlaceHolder id=”PlaceHolderTitleAreaClass” runat =”server”/><script type=”text/javascript” src=”/_layouts/jsscripts/jquery-1.7.min.js”></script>
<script type=”text/javascript” src=”/_layouts/jsscripts/jquery.hoverIntent.minified.js”></script>
<script type=”text/javascript” src=”/_layouts/jsscripts/jQuery/MegaMenuScript.js”></script></head>[/code]
You are calling your javascript files incorrectly.
Please refer to my post here (Relevant quoted below): http://sharepoint.stackexchange.com/questions/68661/how-to-add-jquery-script-to-a-custom-visual-webpart/83063#83063
Here is some example code I used in a control for SOD, in a visual web-part it should be the same.
// Running in a Control added to Master Page
// Register the JavaScript file to the header
ScriptLink.Register(
this.Page,
@”js/ajaxlibrary.js”,
false
);
// But tell the page to load it
// at the end of the page
string clientLoadjaxLibrary =
“LoadSodByKey(‘js/ajaxlibrary.js’);”;
SPPageContentManager.RegisterClientScriptBlock(
this,
this.GetType(),
“clientLoadjaxLibrary”,
clientLoadjaxLibrary
);
for scriptlinks there syntax if you want it loaded on request is:
<SharePoint:ScriptLink language=”javascript” name=”~sitecollection/Site Assets/js/jquery.js” runat=”server” OnDemand=”False” LoadAfterUI=”True” />
also make sure you wrap your JQuery up like so to register it as a global library in sharepoint:
function $_global_jquery() {
//jquery code here
}
calling this function either in a scriptblock on your required page/control or at the bottom of the JS file to load the library:
$_global_jquery();
All custom libraries should be wrapped up with that, also custom namespaces should be registered with SharePoint as well.
On another note JQuery 1.10.2 is the only version that has no conflicts with any part of SharePoint. Older versions throw strange errors from time to time with $ conflicts.
To answer this question. While not a duplicate the answer that shows how to scriptlink by me will prevent several things from breaking in SharePoint 2013. As it stands you are disabling several features as well as breaking the javascript on the page.
You can use delegate control to load jQuery on master page.
Okay, so here we are:
1) Don’t ever put jQuery in master page, suggested copy-pasting methods by scripting kids might be not that optimal. Consider custom actions to register/unregister global scripts across the site collection.
2) Do we really have a file at _layouts/jsscripts/jquery-1.7.min.js?
3) What is the html markup inside the browser? Could you check it? It may be spoiled somehow, so worth to check and see if it is okay.
4) What does Chrome/IE say regarding “missing” files in the network tab? All the files were loaded? 404? Missing or something?
Finally, how do you know that “jQuery was not loaded”? 🙂