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

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

 

I dont think you need .focus method,

When a new tab is opened you are taken on that tab directly, so just use the below like and it should work.

window.open('http://facebook.com/', '_blank');

-Anurag

-Anurag

I have tried this as well but it does not open a new tab / windows

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.

you can open in new tab using below

window.open("http://facebook.com/", '_blank');

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

when I try this the request is created but a new window / tap is not opened so I just get to the next screen in the portal