I am trying to redirect from homepage www.example.com to www.example.com/portfolio/#works
I have tried inserting the id to the
Use this in your index to redirect to the given address.
header("Location: www.example.com/portfolio/#works");
die();
I hope i understood you correctly.
The one that can be considered canonical to navigate to a new URL is
window.location = 'www.example.com/portfolio/#works'
If you want to redirect to a different path, on the same domain, use:
window.location.pathname = '/portfolio/#works'
This is using the location object offered by the History API , Location API
Thank you all for your answers it was really helpful I have successfully completed the task with this code snippet
console.log(document.getElementById(window.location.hash.substring(1)).click());
Now when a user visits the site, click on the expected tab www.example.com/portfolio/#works it redirects to the portfolio page then fetch the hash url (#works) as the new id and click on the tab again automatically
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.