How to handle JavaScript post back in SharePoint 2010
Scenario : Run JavaScript on page load but not on postback.
Why : SharePoint does field validation on server side so it runs page load js again.
Please do not forget to comment if this helps.
Please use below script to avoid same :
$(document).ready(function() {
if((window.location.pathname).toLowerCase().indexOf("new.aspx") > 0) {
if((document.referrer).toLowerCase().indexOf("new.aspx") < 0) {
ExecuteOrDelayUntilScriptLoaded(functionToCall, "sp.js");
}
}
});
function functionToCall()
{
alert('Just on page load');
}
Why : SharePoint does field validation on server side so it runs page load js again.
Please do not forget to comment if this helps.
Please use below script to avoid same :
$(document).ready(function() {
if((window.location.pathname).toLowerCase().indexOf("new.aspx") > 0) {
if((document.referrer).toLowerCase().indexOf("new.aspx") < 0) {
ExecuteOrDelayUntilScriptLoaded(functionToCall, "sp.js");
}
}
});
function functionToCall()
{
alert('Just on page load');
}
Comments
Post a Comment