Portal shortcut opening within frame

VL10
Tera Expert

I have a question regarding the favorite for "Self Service - Switch to Portal" when clicked from the Main App View.

How do we prevent it from opening in a new tab, but open within the same tab, with the favorites still pinned on the left?

 

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

Hi @VL10 ,

 

Hope you are doing great.

 

To ensure that the portal opens within the same tab while keeping the favorites pinned on the left, use UI script. A UI Script allows us to modify the behavior of the user interface elements in ServiceNow.

Reference code:

To implement this code, follow these steps:

  1. Create a new UI Script record 
  2. In the "Script" field, use below code:.

 

function onLoad() {
    // Get the 'Self Service - Switch to Portal' favorite element
    var favoriteElement = document.getElementById('sys_app_sidebar_self_service_switch_to_portal');

    // Add an event listener to override the default behavior
    favoriteElement.addEventListener('click', function(event) {
        event.preventDefault(); // Prevent the default action of opening in a new tab
        window.location.href = '/sp'; // Replace '/sp' with the correct URL of your portal if different

        // Optionally, you can update the favorite's active state to reflect the change
        favoriteElement.classList.add('active'); // Add the 'active' class to highlight the favorite

        // You may need to refresh the left navigation pane to ensure the changes are reflected
        // Add the following line if necessary:
        // top.gsftNav.refreshNavigator();
    });
}
​

 

  • Save the UI Script record.
  • Navigate to the "Main App View" or the corresponding UI page where the favorite is located.
  • Edit the UI page and add the UI Script record you created in the previous step to the "Client Scripts" related list.
  • Save the UI page changes.
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

VL10
Tera Expert

Thank you for your reply.  While this may work I don't think code is required.

Standard bookmark users:  https://INSTANCE.service-now.com/itsm?sysparm_stack=no

However using this will allow it to open within the frame:
https://INSTANCE.service-now.com/now/nav/ui/classic/params/target/itsm%3Fsysparm_stack%3Dno

Perhaps we can edit the link within the bookmark table to do the job?