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
11-09-2021 04:17 AM
Hello
can you help me with the code to open in new window?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:00 AM
Try this code:
Make sure client is checked and onclick function must available:
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
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:09 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:51 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 04:53 AM
also set the property glide.script.block.client.globals as false.