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";
}
sub-page.phplocated in the document root or under some sub folder?window.open("sub-page.php", "_self");