How to open new browser tab from popup modal created by a catalog client script on a catalog item in Service Portal?

patricklatella
Mega Sage

Hi all,

I've got a popup modal that is generated by a catalog client script, everything is working except I can't find the syntax to get the redirect to open in a new browser tab.  Anyone know what I'm missing?  thanks!

Here's the script that opens the modal with the "location.href" that I'm using for now for the redirect...I'm assuming this is not correct.  I've added target="_blank"; 

spModal.open({
title: 'Issue?',
message: 'To report an issue, you need to use a different form in our ESS portal. <p><p>Click the button below to redirect to the correct form.',
buttons: [
{label:'Take me to the correct form', primary: true},
{label:'Stay on this page', cancel: true}
]
}).then(function(){
//populates the "u_practice" field when the cat item opens in ESS portal
location.href='ess/main_content.do?sysparm_content_url=com.glideapp.servicecatalog_cat_item_view.do%3fsysparm_id%3d3f1dd0320a0a0b99000a53f7604a2ef9&sysparm_variables={"u_practice":"34ec3caedbd883006e4d778ebf96198d"}';//this is what I want to open in new tab

target="_blank"; //this does not work
});

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

Hi Patrick,

Window may not be available but top is:

var url = "//your.url.here";

...

   top.window.open(url, '_blank');

...

 

Give that a try. It might work.

View solution in original post

9 REPLIES 9

Barrilito van D
Kilo Guru
Hi Patrick,

Instead of location.href do it like this:

var url = 'your url';

window.open(url, '_blank');

Apart from this, realize that many times if you specify in coding a relative path (as you do as the url starts with /ess/main...) the url will open in the same window. Sometimes it may help already if you specify a full url (with your domain in it and all.  And if you do so, remember another good practice that instead of refering to "http://www.blabla..." or "https://www.blabla..." just use "//www.blabla..."  that way the url it goes to will follow automatically http or https depending on if you are on a http or https site.
Hope it helps or gets you a step further. Good luck!

Hi barrilitovandijk,

thanks for the repsonse, tried your suggestion but unfortunately no luck.  This script is in a catalog client script on a catalog item in Service Portal, where I don't believe the "window" object will work.

 

Hi Patrick,

yes window object won't work in service portal.

https://community.servicenow.com/community?id=community_question&sys_id=afa00765db98dbc01dcaf3231f96...

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

Hi Ankur,

thanks, I'm looking at the reference you provided and not sure it's the same scenario.  I've got a popup, which is written in the script of a catalog client script, which shows a button to link to a different portal.  I want the different portal to open in a new browser tab...are you thinking I can get this to work by updating the menuTemplate?