Issue with top.window.location

pramodkumar
Tera Expert

Hi All,

I am using top.window.location in client scripts to redirect to a specific page which is working fine in regular browsers. When I am testing this is iframes, I see browser console error and also it is not redirecting. Is there any other way we can achieve redirection in iframes?

 

 

Thanks@

4 REPLIES 4

Ravi Gaurav
Giga Sage
Giga Sage

Hi @pramodkumar 

When you use top.window.location in a client script, it tries to redirect the entire top-level browser window. This works fine in normal browser usage but fails inside an iframe, because most browsers block cross-frame navigation for security reasons (known as the “same-origin policy” and X-Frame-Options restrictions). That’s why you see console errors and no redirection.

If you want to redirect only the iframe content (not the parent window), you should use window.location instead of top.window.location. For example:

window.location = '/desired_page.do';

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

kaushal_snow
Mega Sage

Hi @pramodkumar ,

 

 

Modern browsers like Chrome block top level iframe navigation for security reasons. If you're trying to redirect the parent window via top.location, it may be silently blocked.


Solutions to Redirect Effectively...

 

Option 1: Use setTimeout with top.window.location in client script

Option 2: Redirect the Parent Window via a Clickable Link

 

If programmatic control is limited, you can present users with a link that opens the target page as the top level window:

 

<a href="targetURL" target="_top">Click here to proceed</a>

 

Follow below articels:

 

https://help.alchemer.com/help/break-out-of-iframe

 

https://stackoverflow.com/questions/2092275/redirect-the-parent-page-from-iframe/2092289

 

https://www.servicenow.com/community/developer-forum/quot-top-window-location-quot-not-working-in-on...

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

RaghavSh
Kilo Patron

1. "top.window.location" is DOM it do work in regular client scripts with isolate script.

2. It is intended to load the browser which means parent of iframe , iframe is another code which is just displayed on some other web page. The redirection will fail here.

3. I dont think there is a solution to this.


Raghav
MVP 2023
LinkedIn

@pramodkumar did this solve your query?


Raghav
MVP 2023
LinkedIn