i like to do a simple javascript execution with MDS and without MDS.
To do this, I have used this Javacript only executed on first page load HowTo to get work.
The Problem i have, is that the script only is run once time. With a MDS Delta and a direct invoke.
/sites/sitecollection/_layouts/15/start.aspx#/SitePages/test.aspx
/sites/sitecollection/SitePages/test.aspx
Both link works great for one time. When i now go to home and back to the test link, my script will not run.
Here are my scripts:
TEST.ASPX
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<meta name="CollaborationServer" content="SharePoint Team Web Site" />
<SharePoint:ScriptBlock runat="server">
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/jquery.min.js" OnDemand="false" runat="server" Localizable="false"/>
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/mycode.js" OnDemand="false" runat="server" Localizable="false"/>
var navBarHelpOverrideKey = "WSSEndUser";
</SharePoint:ScriptBlock>
<SharePoint:RssLink runat="server" />
</asp:Content>
MYCODE
function myCode(){
// jQuery code goes here
// you can use $ namespace
alert("Hello");
}
function preCode(){
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(myCode);
}
if(typeof _spPageContextInfo != "undefined" && _spPageContextInfo != null){
var jsURL = _spPageContextInfo.siteServerRelativeUrl + "/SiteAssets/mycode.js";
RegisterModuleInit(jsURL, myCode());
}else{
ExecuteOrDelayUntilScriptLoaded(preCode, "sp.init.js");
}
Can anyone tell me my fault? I am frustrating.
Thanks for all your help.