Why is window null in Desktop (Snow UI) and Mobile/Portal?

German Monsalve
Giga Contributor

Based on docs (https://docs.servicenow.com/bundle/madrid-servicenow-platform/page/build/service-portal/concept/unsu...) I created a Catalog Client Script that run in ALL (mobile and Desktop). In the script I want to know when the script is running on mobile/portal or Desktop, since Desktop code will not work on Portal/mobile.
I am using the following condition:
if(window===null){

alert("portal/mobile");

}else{

alert("Desktop");

}

But window is ALWAYS null, I do not know what to do I will appreciate your help. 

2 REPLIES 2

Mike Patel
Tera Sage

Otherway to do it try and catch

 

 try {
//Works in non-portal ui
} catch(e) {
//For Service Portal
}