I am trying to load a link after 4 seconds after click. Javascript and link are below
<script>
function myFunction()
{
setTimeout(function(){window.location.assign(this.getAttribute('href'))},4000);
}
</script>
<a href="" onclick="myFunction(); return false">
But its not working. How can i solve this. Thanks for your answers.
I am trying to load a link after 4 seconds after click. Javascript and link are below
<script>
function myFunction()
{
setTimeout(function(){window.location.assign(this.getAttribute('href'))},4000);
}
</script>
<a href="http://www.foo." onclick="myFunction(); return false">
But its not working. How can i solve this. Thanks for your answers.
Share Improve this question asked Jan 15, 2014 at 2:52 robintonrobinton 755 silver badges14 bronze badges 1- Why do you want to do this and break how browsers work, including Ctrl-click? – Matijs van Zuijlen Commented Dec 19, 2017 at 12:58
1 Answer
Reset to default 7You need to pass the clicked element reference to the click handler
<a href="http://www.foo." onclick="myFunction(this); return false">
then
function myFunction(el) {
setTimeout(function () {
window.location.assign(el.getAttribute('href'))
}, 4000);
}
or using jQuery
function myFunction(el) {
setTimeout(function () {
window.location.assign($(el).attr('href'))
}, 4000);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744363284a4570574.html
评论列表(0条)