Checking the Web Part page design mode
In this series of blogs, I’ll share some the practices I use to write better JavaScript to customise Project Online screens.The first tip is about detecting the web part page edit mode. Frequently, we write scripts to manipulate UI of the page and if the user is already editing the page, our script can cause undesired behaviour.
We could either execute a different set of functions or at minimum, just not execute the script in design mode to keep the user experience clean.
Its relatively simply to detect the WebPart page design mode. Just add the following code to the startup your script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_spBodyOnLoadFunctionNames.push("myScriptStartup"); | |
function myScriptStartup () { | |
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value; | |
if (inDesignMode == "1") { | |
// page is in edit mode | |
// Do things differently here | |
console.log('Page is in edit mode. so we will not execute the custom script'); | |
} | |
else { | |
// regular script execution goes here | |
} | |
} |
0 comments:
Post a Comment