- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 11:43 AM
Good afternoon,
I used the script below within an onLoad catalog client script for a record producer to open a modal window. I want to close the popup window when the user selects the browser back button. I tried modalInstance.dismiss(); but it is not working. I would appreciate your input for a solution. Thanks!
var returnURL = "some URL";
var modalInstance = spModal.open({
backdrop: true,
keyboard: false,
noDismiss: true,
message: txtContent,
title: 'Popup Title',
size: 'lg',
buttons: [{
label: 'I Agree',
primary: true
},
{
label: 'I Disagree',
cancel: true
}
]
}).then(function() {
// user agrees
}, function() {
top.window.location.replace(returnURL);
}, function() {
spModal.open({
widget: 'widget-id'
});
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 02:10 PM - edited ‎03-24-2025 02:12 PM
I found a workaround for now. It is ugly. I just reload the window when the user selects the back button to get rid of the spModal. I was able to fix the addListesner issue by preceding window with top. I will keep digging until I can close the spModal but for now the users have to live with the workaround. Here's the working code:
top.window.addEventListener('popstate', function(event) {
if (modalInstance) {
top.window.location.reload();
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 02:10 PM - edited ‎03-24-2025 02:12 PM
I found a workaround for now. It is ugly. I just reload the window when the user selects the back button to get rid of the spModal. I was able to fix the addListesner issue by preceding window with top. I will keep digging until I can close the spModal but for now the users have to live with the workaround. Here's the working code:
top.window.addEventListener('popstate', function(event) {
if (modalInstance) {
top.window.location.reload();
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 12:43 PM
What is the spModal for? What's the use case? Using the back button is definitely NOT a great idea.
Can you switch things around to use variables right at the top of the RP for the users to answer before anything else is shown?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 12:52 PM
Hello Jim,
The spModal is to display several paragraphs of acknowledgement text for the user to agree before continuing. The spModal is working fine. But if the user clicks the back button before acknowledging, it returns the user back to the previous page and the modal still stays on the screen.