Hello Friends,
Today we are going to explore a very interesting topic. SharePoint Online: Identify Current Page is Modern page or Classic page. We are going to learn How to identify a current page is classic page or a Modern page in sahrepoint online.
It is a very easy process in SharePoint online to identify current page is Modern page or Classic page. I will explain how to detect the current page is a modern site page or not.
The SharePoint Online itself has a special variable property called _isSPSitePage to identify the type of a page.
This (_isSPSitePage) special variable can be accessed only from the Modern SharePoint site pages. We don’t find this variable in any SharePoint classic pages like a wiki page, web part page, or other pages.
We can also access this variable from SharePoint Extensions like Application Customizer, Command Sets ..etc. This becomes very useful when we writes code based on page types.
Try this below code, which is very useful if you want to identify the page type. Follow the below steps to test this code.
Steps:
- Navigate to SharePoint site where you want to check the file type.
- Open browser web console by pressing F12 button from keyboard
- Copy and paste below code into your console.
var modernPage = false;
try{
if(window._isSPSitePage)
{
modernPage = true;
console.log("This is a modern site page");
}
else{
console.log("This is a Classic site page");
}
}
catch(e){}
In this way, we can determine the current page is a modern site page or a Classic site page in SharePoint Online.
I hope you like this tutorial. If yes then please like and share this page. Comment below your doubts related to this topic.
You can also explore our other tutorials, hope you like it.
- SharePoint Online: Edit Permission Level with CSOM PowerShell
- Connect MFA enabled SharePoint site using CSOM
- Retrieve SharePoint List Items using CSOM
- Get Current Context from SharePoint Modern Site Page
- How to Convert Site Page into News Post in SharePoint Online?
- Register application in Azure portal – Part II
- What is Required Toolchain for SharePoint Framework
- Search In SharePoint Online
2 thoughts on “SharePoint Online: Identify Current Page is Modern page or Classic page”