redirect to a new tab form a client script

alexrozov
Tera Expert

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

 

14 REPLIES 14

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

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

can you try with below code. 

 

function onSubmit() {

location.href="http://facebook.com";
}

alexrozov
Tera Expert

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

Munender Singh
Mega Sage

Hi,

Use this :

g_navigation.open();

 

Regards,

Munender