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.

SharePoint Online: Identify Current page is Modern Page or Classic Page

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:

  1. Navigate to SharePoint site where you want to check the file type.
  2. Open browser web console by pressing F12 button from keyboard
  3. 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){}
SharePoint Online: Identify Current Page is Modern page or Classic page

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.

Leave a Reply