redirect to a new tab form a client script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 03:08 AM
Hi All
I'm trying to create a catalog item that will redirect to a different web page based on a selection in a variable.
I have created the following onsubmit client script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var URL = 'http://facebook.com/';
top.window.location = URL;
}
this works, but it redirects the current tab and throws me away from ServiceNow.
I would like to get facebook opened in a new tab/windows and I have tried a number of ways as listed below but none of these are working
1.
var win = window.open('http://facebook.com/', '_blank');
win.focus();
2.
win = window.open("http://facebook.com/", '_blank');
3.
window.open("http://facebook.com/", '_blank');
4.
$window.open("http://facebook.com/", '_blank');
5.
var URL = 'http://facebook.com/';
window.location.href(URL);
6.
var URL = 'http://facebook.com/';
window.open(URL);
7.
var URL = 'http://facebook.com/';
windows.location.assign(URL);
but none of these work for me
Any help would be appreciated
Alex
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:56 AM
if its not available on properties table , create it and set it has false.
HI article for further details
https://hi.service-now.com/kb_view.do?sysparm_article=KB0551586

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:37 AM
got a bit further
I added my instance URL as allowed for popups in the chrome settings.
now it works perfectly from the technical view
but from the portal I'm still getting a javascript error
adding the property you have suggested did not change anything - still works from the technical view and does not work from the portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 05:51 AM
can you try with below code.
function onSubmit() {
location.href="http://facebook.com";
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 07:07 AM
Hi All
finally I got this to work.
I had 2 things I needed to do
1. make sure my instance is allowed for popups on the browser
2. looks like the window object is not working in the portal (see https://community.servicenow.com/community?id=community_question&sys_id=608bc361db9cdbc01dcaf3231f96...)
so eventually what worked for me was
function onSubmit() {
//Type appropriate comment here, and begin script below
top.window.open("http://facebook.com");
}
thanks everyone for the ideas and support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 08:33 AM
Hi,
Use this :
g_navigation.open();
Regards,
Munender