I have javascript code included in my sharepoint site. When I load the page the first time, it is executed, but when I load it the second time, it is not running. It get's loaded in correct order but the functions inside are not executed (but only on second load)
The first time I load the page by entering the url in the webbrowser, the second time I load the page by clicking the link inside sharepoint website (same url). It seems to me that this problem occurs because it is not a complete pageload. Looks like some ajax magic to me.
This is how I have implemented the js ressources: In my aspx file I have those lines:
<asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/js/jquery.min.js" OnDemand="false" runat="server" Localizable="false" LoadAfterUI="false"/>
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/js/newoverview.js" OnDemand="false" runat="server" Localizable="false" LoadAfterUI="true"/>
<SharePoint:CssRegistration ID="CssRegistration3" Name="<% $SPUrl:~site/SiteAssets/css/newoverview.css%>" runat="server"/>
<SharePoint:RssLink runat="server"/>
jquery.min.js
function $_global_jquery() {
//jQuery code goes here
}
$_global_jquery();
newoverview.js
_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
function runAfterEverythingElse(){
/* my code */
html = 'test';
jQuery('table[summary="test"]').html(html);
}
Take note that my code is working, as I can see it working when loading the page the first time!
The question
Why is the javascript not executed when opening the page inside sharepoint?