Hide URL in Popup Window with window.open
By FoxLearn 2/8/2025 3:02:50 AM 57
If you'd prefer to hide this URL from your users, here’s an approach you can follow.
window.open("myPopupWindow.html", "_blank", "height=400, width=550, status=yes, toolbar=no, menubar=no, location=no, addressbar=no, top=200, left=300");
In case you're trying to hide the address bar to make the popup look cleaner or to prevent users from seeing the direct URL, you might not want them to know they can access the content outside of the popup.
One approach is to load the page inside an iframe
within the popup. This way, the user sees only the content inside the iframe, and the URL remains hidden.
window.open('http://xyz.com/welcome.html');
Then, in your welcome.html
, you can include this code:
<html> <body> <iframe src="/hiddenContent.html" style="border:none; width:100%; height:100%;"></iframe> </body> </html>
This ensures that the content in /hiddenContent.html
is loaded within the iframe, and users won't see the actual URL of the page in the address bar.
If you prefer opening a new tab instead of a popup, you can use the following code:
window.open('', '_blank').location.href = "newPage.html";
This will open a new tab and direct it to the newPage.html
URL.