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 03:12 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 03:56 AM
I have tried this as well but it does not open a new tab / windows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 03:21 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

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