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

Hello @Ankur Bawiskar ,

 

can you help me with the code to open in new window?

 

Thanks in advance!

AbhishekGardade
Giga Sage

Try this code:

Make sure client is checked and onclick function must available:

find_real_file.png

function openPortal(){
var catItem = 'dd9820361b033300364d32a3cc4bcbbe';
var url = '/sp?id=sc_cat_item&sys_id='+catItem;
window.open(url,'_blank');

}

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Harsh Vardhan
Giga Patron

can you confirm here, are you using catalog client script to redirect to facebook page ?

 

if yes, please set the "isolate script" field as false and then try. 

 

find_real_file.png

 

Note: if "isolate script" field is not available on form you can add it by configure >> form layout 

Yes, I am trying to do this from a client script

 

did exactly like yours as you can see in the picture and when I hit submit from the portal I get a "javascript error", the request is created but the new tab/window does not open

When I try to use "try it" from the technical view nothing happens and I stay on the form not getting any error message

find_real_file.png

also set the property glide.script.block.client.globals as false.