Muhammad Khan
Mega Sage
Mega Sage

I guess there is some confusion regarding top, window and document objects in Native UI and Service Portal. So, sharing my observations regarding these during some testing in PDI.

function onLoad() {

    if (window === null) { // For portal
        
		//top.location.href; will work in portal
		//top.window.location.href; will work in portal
		//top.document.location.href; will work in portal
		//window.location.href; will not work in portal because window is null in portal
		//document.location.href; will not work in portal because document is null in portal
		
		alert('Portal  Top: ' + top.location.href);
		alert('Portal Top.Window: ' + top.window.location.href);
		alert('Portal Top.Document: ' + top.document.location.href);
		alert('Document Object: ' + document);
		alert('Window Object: ' + window);
		alert('Top Object: ' + top);
		
    } else { // For Native UI
		
		//top.location.href; will work in Native UI
		//top.window.location.href; will work in Native UI
		//top.document.location.href; will work in Native UI
		//window.location.href; will work in Native UI
		//document.location.href; will work in Native UI
		
		
		alert('Native UI Top: ' + top.location.href);
		alert('Native UI Top.Window: ' + top.window.location.href);
		alert('Native UI Window: ' + window.location.href);
		alert('Native UI Top.Document: ' + top.document.location.href);
		alert('Native UI Document: ' + document.location.href);
		alert('Document Object: ' + document);
		alert('Window Object: ' + window);
		alert('Top Object: ' + top);
    }	
}
  1. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = All
    • Isolate = False
    • Execution
      • If block will be executed in portal, else block will be executed in Native UI.
  2. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = All
    • Isolate = True
    • Execution
      • If block will be executed in portal and Native UI both, else block will not be executed in portal and Native UI.
      • window and document will be null, to access them top will be used.
  3. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = Desktop
    • Isolate = False
    • Execution
      • No block will be executed in Portal, else block will be executed in Native UI.
  4. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = Desktop
    • Isolate = True
    • Execution
      • No block will be executed in Portal, if block will be executed in Native UI.
      • window and document will be null, to access them top will be used.
  5. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = Mobile / Service Portal
    • Isolate = False
    • Execution
      • No block will be executed in Native UI, if block will be executed in Portal.
      • window and document will be null, to access them top will be used.
  6. Catalog Client Script Configuration:
    • Catalog Client Script UI Type = Mobile / Service Portal
    • Isolate = True
    • Execution
      • No block will be executed in Native UI, if block will be executed in Portal.
      • window and document will be null, to access them top will be used.

 

Interested in reading my other articles, go through the below link.

Useful Implementation for Service Portal and Native UI

 

 

Always open to learn new things.

Happy Learning

Comments
G24
Kilo Sage

@Muhammad Khan Fantastic.  Thank you.

 

1)  So does this mean that the "document" and the "window" objects are always available via "top"?

2)  Also, can this information be used to somehow reliably determine, inside the script itself, if it is running in the context of the Service Portal VS the Platform UI?  If so, please explain.  Thanks!

Version history
Last update:
‎09-10-2022 07:53 PM
Updated by: