jquery - How to set this.getAttribute('href') in this javascript? - Stack Overflow

I am trying to load a link after 4 seconds after click. Javascript and link are below<script>func

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
Add a ment  | 

1 Answer 1

Reset to default 7

You 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信