Is it possible to link to another web page and then call a function on that webpage? We have two pages and we would like to have a button that sends you to a specific part of the other page and would hence have to both send the user to the correct page and call a function on that page.
Is this at all possible? We do already have a document ready function and we do not want to go to this specific part of the page everytime we enter it, only if you come from the other page. Can you send some kind of variable with a link? Then we could write and if-statement to avoid calling our function every time the document loads.
We are coding in JavaScript and can use jQuery.
I've done this several times using the method @Marc suggested in comments.
<a href="new_page#some_id">Link</a>
On the second page:
<div id="some_id">Content</div>
<script>
if (window.location.hash === '#some_id') {
call_function();
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With