How can I mask the redirected URL on my special offers page?

I have a ‘currently on-special’ page on my site which redirects using window.location.assign to the product that I have decided is the ‘special’ this month. But I want the address bar to remain as the ‘on-special page address’ so that when people copy and paste the url it is taken to whatever the current ‘special product is’, at the moment the url then shown is the one redirected to…how can I achieve this:

EG/
So user enters www.website.com/page/specials as the address

window.location.assign sends to www.website.com/products/abcd

but address is then shown as www.website.com/products/abcd and I want it to still be www.website.com/page/specials

so that when the link is shared it is for the specials page, not the actual product ?

Can anyone help?

To achieve the desired behavior of keeping the URL in the address bar as the “specials” page URL even after redirecting to a specific product, you can use the HTML5 History API’s pushState method. This method allows you to change the URL displayed in the address bar without actually navigating to a new page.

Here’s an example of how you can modify your code to achieve this:

// Get the current URL of the specials page
var specialsPageURL = window.location.href;

// Get the URL of the "special" product
var specialProductURL = 'www.website.com/products/abcd'; // Replace with your actual special product URL

// Redirect to the special product URL
window.location.assign(specialProductURL);

// Change the URL in the address bar to the specials page URL
window.history.pushState(null, null, specialsPageURL);

Thanks but this still shows the www.website.com/products/abcd in the address bar …I have added this code to the template of the ‘specials page’ and the redirect is working, but it is not ‘masking’ the address bar…I also tried the pushState on the produt template (as I figured that the assign would get rendered before the pushstate and so perhaps never get to it) but that didn’t work either…I am not sure why this isn’t working :disappointed_face: