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 e 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.
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 e 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.
Share Improve this question edited Jul 5, 2018 at 7:09 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Nov 17, 2015 at 13:21 e.klara.ke.klara.k 3791 gold badge6 silver badges17 bronze badges 2-
Sure. Consider putting a hash property in the href, and then have the target page read the hash property. In the document.ready, perform the action if you find the specified hash property in the URL.
location.hash
reads hash properties from the URL. – Marc Commented Nov 17, 2015 at 13:24 - Yes, that's possible so long as the receiving page can read either a hash, cookie, localStorage or a variable held in either POST or GET (in the URL). How far did you get when you tried to implement this? – David Thomas Commented Nov 17, 2015 at 13:24
1 Answer
Reset to default 8I've done this several times using the method @Marc suggested in ments.
<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>