I have a JS script that appends to the HTML page the pairs: input + anchor
Can I compute the URL before the redirect happens?
Now I have link that looks like this:
<a href="#" onclick="myFunct();return false;">link</a>
and myFunct
uses window.location.href
to redirect webpage. The problem with this approach is that I cannot (obviously) CTRL+click on the link for opening goal link in a new tab.
Details:
The link URL is known after obtaining the URL from the server - this operation is very expensive for me and I would like to do that only in case it is absolutely necessary.
The idea is: user chooses a link, he/she clicks it, url is obtained from server and user is redirected (in the same window or in a new tab if he/she uses CTRL+click)
Thanks!
Im not entirely certain this is what you are looking for by try giving your anchor an id
<a href="#" id="mylink">link</a>
then just update the href
attribute to change the new location (perhaps on change on an input ?
<input onchange="changeLink(this)" value="http://www.google.com/"/>
function changeLink(elem) {
var mylink = document.getElementById('mylink');
mylink.href = this.value; // you could prepend your value with a domain
}
Every time the value in the input
changes the href will be changed to match
instead of navigating with the onmousedown, you can just rewrite the href
<a href='http://www.google.com' id='computed_link' onmousedown='handleClick()'>Computed Link!!</a>
<script type='text/javascript'>
function handleClick()
{
document.getElementById('computed_link').href = 'http://www.yahoo.com';
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With