Open a URL in background in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 06:53 AM
HI,
In Service portal, When user clicks on Ok in the alert popup, i would like to open a URL in the background and not redirect the user to the url. (the user should still be on the current window). Is this possible? If so, can you please suggest how this can be done?
I've tried window.focus() but it din't work
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 07:37 AM
Hi @Neha79
I think it is not that straightforward due to browser security restrictions.
Maybe you can try using using a hidden iframe or making an asynchronous request (e.g., with XMLHttpRequest or Fetch API) to load the content without affecting the main user interface.
something like this -
function openUrlInBackground(url) {
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src=url;
document.body.appendChild(iframe);
// maybe remove the iframe after it has loaded (or after a timeout)
iframe.onload = function() {
document.body.removeChild(iframe);
};
}
// Example usage
openUrlInBackground('https://google.com');
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar