You are working in a browser environment and must use vanilla JavaScript only (no external libraries).
Task
Implement a function showPopupAndRedirect(message, targetUrl) that does the following:
-
Immediately shows a popup dialog to the user displaying the given
message
.
-
After the user closes the popup, the current page should redirect to
targetUrl
.
Requirements
-
The popup must be created using only built-in browser APIs (for example,
alert
,
confirm
, or a custom DOM-based modal that you implement yourself).
-
The redirect must be done using standard browser navigation (e.g., assigning to
window.location
or a similar mechanism).
-
If
targetUrl
is not a non-empty string, the function should
not
attempt to redirect.
-
Assume this code runs in a modern browser with JavaScript enabled.
You do not need to handle errors beyond the simple validation of targetUrl described above.
Describe the implementation and then provide the JavaScript code for showPopupAndRedirect.