logo

NJP

Top Window Document Objects in Native UI and Service Portal

Import · Sep 11, 2022 · article

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

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/top-window-document-objects-in-native-ui-and-service-portal/ta-p/2317667