Tell me, please, how to implement it so that the link works only once, during the second and other clicks, a transition to another page was carried out.
- If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦
- 2let's help phishers too - strangeqargo
|
3 answers
javascript:
<script type="text/javascript"> function myFunc() { if(!localStorage.getItem("Ключ")){ localStorage.setItem('Ключ', '1');//ключ undefined, то переходим по первой ссылке, если ключ есть, то по второй window.location = "http://ru.stackoverflow.com"; } else {window.location= "http://stackoverflow.com";} } </script> html:
<button onclick="myFunc()">Нажми меня</button><br /> |
Script:
<script type="text/javascript"> function ChangeLink() { $('#link').attr('href', 'http://www.google.com/'); } </script> Link:
<a href="http://www.yandex.ru/" onclick="ChangeLink()" id="link" target="_blank">text</a> Or:
<a href="http://www.yandex.ru/" onclick="$('#link').attr('href', 'http://www.google.com/')" id="link" target="_blank">text</a> |
In my opinion, everything can be done even easier:
<a href="startHref" target="_blank" onClick="javascript:this.href='secondHref'">href-title</a> |