# JavaScript to redirect specific page

**URL:** <https://forums.knack.com/t/javascript-to-redirect-specific-page/8368>\
**Category:** Ask Developers\
**Created:** [August 12, 2020, 11:21am UTC](https://forums.knack.com/t/javascript-to-redirect-specific-page/8368 "2020-08-12T11:21:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KimberlyNi07205](https://avatars.discourse-cdn.com/v4/letter/k/ccd318/32.png) [@KimberlyNi07205](https://forums.knack.com/u/KimberlyNi07205)\
**Post date:** [August 12, 2020, 11:21am UTC](https://forums.knack.com/t/javascript-to-redirect-specific-page/8368/1 "2020-08-12T11:21:03Z")

</div>

Hello,

I have a dropdown menu in our database, but unfortunately, when you click on the actual dropdown title, it leads to a blank page. There seems to be no way to edit that page, so I want to redirect it to the first page in the dropdown.

I'm really not good with JavaScript, but this is what I have so far:

&nbsp;

$(document).on('knack-scene-render.scene\_809', function(event, scene) {  
if (window.location.hash.indexof("#resume-builder") != -1) {  
window.location.replace("[https://website.com](https://website.com)");  
}  
else {}  
});

&nbsp;

Any ideas why the above doesn't work? I've tried a bunch of variations, but this seems to be as far as I can get. Thank you in advance!

---

<div class="post-metadata">

**Author:** ![KimberlyNi07205](https://avatars.discourse-cdn.com/v4/letter/k/ccd318/32.png) [@KimberlyNi07205](https://forums.knack.com/u/KimberlyNi07205)\
**Post date:** [August 14, 2020, 12:58pm UTC](https://forums.knack.com/t/javascript-to-redirect-specific-page/8368/2 "2020-08-14T12:58:36Z")

</div>

In case anyone is interested, 380030416312&nbsp;posted the correct code here:

[https://support.knack.com/hc/en-us/community/posts/115000049411-Dropdown-Menu-Link](https://forums.knack.com/hc/en-us/community/posts/115000049411-Dropdown-Menu-Link)

&nbsp;

$(document).on('knack-scene-render.scene\_284', function(event, scene) {&nbsp;  
window.location.href = "https://......";  
});

Replace 'scene\_284' with the scene number of your drop-down menu and add your redirect URL.

&nbsp;

It worked beautifully for me.&nbsp;

---

<div class="post-metadata">

**Author:** ![evan](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evan](https://forums.knack.com/u/evan)\
**Post date:** [January 3, 2022, 2:26pm UTC](https://forums.knack.com/t/javascript-to-redirect-specific-page/8368/3 "2022-01-03T14:26:20Z")

</div>

`window.location.replace('http://example.com');`

It’s better than using window.location.href = ‘[http://example.com](http://example.com)’;

Using replace() is better because it does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.

If you want to simulate someone clicking on a link, use window.location.href

If you want to simulate an HTTP redirect, use window.location.replace

You can use assign() and replace methods also to [JavaScript redirect](http://net-informations.com/js/iq/load.htm) to other pages like the following:

`location.assign("http://example.com");`

The difference between replace() method and assign() method(), is that replace() removes the URL of the current document from the document history, means it is not possible to use the “back” button to navigate back to the original document. So Use the assign() method if you want to load a new document, andwant to give the option to navigate back to the original document.
