When i click a link, i want to execute a javascript function to get the dynamic url. So i did like below.
a link
Short answer: No, you can't.
But since you are using JS anyways, you can just use it to change the href attribute in <a, so by the time the user clilcks on the link, it's already pointing to the right URL.
href
<a