Javascript Detect SharePoint Page In Edit Mode
In this post I am going to explain different ways to detect SharePoint page mode through client side scripts
If the page is publishing then we can query following JavaScript variable to find the Page status
if(g_disableCheckoutInEditMode == true) {
alert('Page is in edit mode');
}
else {
alert('Page is in display mode');
}
Another options for publishing page
//Add following in master page <script type="text/javascript"> var IsEditMode = false; </script> <PublishingWebControls:EditModePanel runat="server" id="EditModePanelToFindEditMode"> <script type="text/javascript"> IsEditMode = true; </script> </PublishingWebControls:EditModePanel> //Now through script you can use the variable IsEditMode
We can also query the PageState object which has property ViewModeIsEdit. The problem with this is because the object gets initialized only after loading sp.ribbon.js.
Another option
var IsEditMode =
document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (IsEditMode == "1") { // page is in edit mode }
else { // page is in browse mode }
For WIKI pages
var IsEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
if (IsEditMode == "Edit") {
// wiki page is in edit mode
} else { // wiki page is not in edit mode }
Categories: jQuery, SharePoint 2010
Comments (1)
Trackbacks (0)
Leave a comment
Trackback
