K
K
Kornely2022-01-10 23:17:47
AJAX
Kornely, 2022-01-10 23:17:47

Is it possible to call a Jquery function from a link to another page?

Let's say if page1 and page2 are ("physical" pages, not JS). Page1

has a link to page2 . And page2 has an Ajax function that needs to be called from a link on the first page. If the function is on the same page as the link, it's easy. But if on the other - it does not work. Tried, for example, like this: Does not work.



<a href="page2" onclick="foo()">Link</a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2022-01-10
@Korneliy

The functionality is implemented within some section of the code. Connect this code to
page1 and you will be happy.
PS If you need a click to first transition, and then the function is called, then you do it like this:
For example, page2?doFooPlease=1
2. In the js code on page2, check if the address bar contains the doFooPlease parameter. If it exists and its value is equal to 1, then call your foo()
3. As a bonus, using historyAPI, you can throw out the now unnecessary doFooPlease=1 so as not to offend the highly aesthetic appearance of the address bar with these ugly parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question