Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link with href and call function on new page

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.

like image 756
e.klara.k Avatar asked Mar 14 '23 03:03

e.klara.k


1 Answers

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>
like image 77
Ben Cook Avatar answered Mar 25 '23 01:03

Ben Cook