Z
Z
ZyL2011-09-21 02:52:50
JavaScript
ZyL, 2011-09-21 02:52:50

jQuery: how to track the transition to another page by executing JavaScript code?

There is a need to add something to the address that leads to another page. Those. the user clicked on the link or clicked on the button, and JS adds one more parameter (token) to the URL - actually fighting XSS.

How to track regular <a, <form, etc. understandably. But what if the transition is carried out on the execution of onclick? It seems like you need to track the “change” event for window.location, but as I understand it, this cannot be done.

Neither I nor my colleagues are specialists in JS, we know it in so far as we scratch our turnips and cannot think of it. The application is awesome in size and written very crookedly, we will look for all occurrences of JavaScript until the second coming.

No one will help with scary knowledge?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
D
dmitryklerik, 2011-09-21
@dmitryklerik

Maybe the jQuery 'unload' event will help you: api.jquery.com/unload/ ?

S
sl_bug, 2011-09-21
@sl_bug

In each place where there is a window.location change, add what you need.

Z
zolotyh, 2011-09-21
@zolotyh

In Chrome,
window.onbeforeunload = function (event) {console.log(event.target.URL); return false;}

Z
ZyL, 2011-09-21
@ZyL

This option is always available. But I hope for a miracle and a guru.

Z
ZyL, 2011-09-21
@ZyL

No, it doesn't help, we tried it - window.location remains the same. Here one pretzel writes about event handling, as it were: But it works (and the example is the same) only on ordinary links like <a, it doesn’t work on JavaScript. In addition, he writes there that As you know, window.location is a Javascript object that contains information about the URL including hash and search strings. Those. it's not an HTML object, but Javascript, i.e. like how JQuery cannot be configured to process it?
$( window.location ).trigger(
"change",
{
currentHref: strLocation,
currentHash: fnCleanHash( strHash ),
previousHref: strPrevLocation,
previousHash: fnCleanHash( strPrevHash )
}
);

1
1nd1go, 2011-09-21
@1nd1go

There is a standard callback - window.onbeforeunload. I think you can change where to go there.
jquery plugin here: plugins.jquery.com/plugin-tags/windowonbeforeunload

Z
ZyL, 2011-09-21
@ZyL

— * 1nd1go Looks
like something useful, thanks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question