Secrets behind SharePoint Online – How to identify the current page is modern or not

How to detect the current site page is modern or not. Check out this blog post to know about that.

Do you want to identify whether the current page is a modern page or not? Then here it is a place. I’ll explain how to detect the current page is a modern site page or not. The SharePoint itself has a special variable called  _isSPSitePage to identify the page type.

We can access this variable only from modern sites pages and can’t be accessible from classic pages like a wiki page, web part page and other List View pages…

We can also access this variable from SharePoint Extensions like Application customizer, Command Sets,… This may useful when we want to write the code based on the site page types.

The below code is useful if we want to identify the page type. To test it, navigate to the SharePoint site and open the browser web console and paste the below code.

Check out the below video which explains the same.

 

Shantha Kumar
Shantha Kumar
Articles: 280