About the behavior of "URLSearchParams"

bonsai
Mega Sage

I'm developing a portal screen that I intend to display in the platform's content frame.

I tried to get the URL using "var urlParams = new URLSearchParams(decodeURIComponent(top.location.search));" in the catalog client script, but nothing was retrieved.

The portal screen works fine if I display it in a separate tab instead of the content frame.

Is there any difference in behavior?

<Example of displaying a portal screen in the platform content frame>

bonsai_0-1771457848483.png


<Normal portal screen>

bonsai_1-1771457914855.png

 

 

1 REPLY 1

Santhana Rajhan
Mega Sage

To get the ServiceNow platform URL from a content frame (iFrame), you need to access the top-level window from within the frame. This is necessary because the content frame is often inside nav_to.do, which hides the base instance URL

 

// Get the base URL (e.g., https://instance.service-now.com)
var platformURL = window.top.location.origin;

// Alternative to get full URL including relative path
var fullUrl = window.top.location.href;

// or just
var URL = window.top.location;

 

Are you trying Catalog Client script?