I am having trouble redirecting from one page to another on button click using javascript?
say, for example, one page is index.php
and another is sub-page.php
, how can I redirect to the subpage from the home page using javascript? can anyone please guide me? files are located in the root directory of my project.
I had already tried following code but it is not working :
HTML code :
<button type="button" onclick="test()">click me</button>
js code :
function test(){
window.location.href = "./sub-page.php";
}
My Answer:
html
Redirect Page
Make sure that both `index.php` and `sub-page.php` are in the root directory of your project. When you click the button, it should redirect you to the `sub-page.php` page.
Rate this post
5 of 5 based on 3208 votesComments