How to do this redirect.

JJ228

Newbie
Joined
Apr 26, 2014
Messages
14
Reaction score
0
Hello,

I have a button on my site, I want user to be redirect after x seconds once the button is clicked.

Can anyone please share the code.

Thanks
 
This could easily be achieved in jquery:-
<script>
$("#buttonid").click(function() {
$(location).attr('href', 'website address / url to redirect to').delay("time in milliseconds");
});
</script>
To use the above add the id "buttonid" to the item you wish people to click, change the website address / url and adjust the time in milliseconds.

I have not run the code, though jquery is pretty simple.

Hope it helps.
 
This could easily be achieved in jquery:-
<script>
$("#buttonid").click(function() {
$(location).attr('href', 'website address / url to redirect to').delay("time in milliseconds");
});
</script>
To use the above add the id "buttonid" to the item you wish people to click, change the website address / url and adjust the time in milliseconds.

I have not run the code, though jquery is pretty simple.

Hope it helps.

Thanks, I don't know much coding, just simple html.

This is my button code - <div class="fb-share-button" data-href="http//MYDOMAINdotcom" data-type="button"></div>

Can you implement the code with my button for me.

Thanks alot.
 
on the internet you will find some generators who will do that
 
Thanks, I don't know much coding, just simple html.

This is my button code - <div class="fb-share-button" data-href="http//MYDOMAINdotcom" data-type="button"></div>

Can you implement the code with my button for me.

Thanks alot.

Simply change the jquery, where I have used "#buttonid" change this for ".fb-share-button", would you like the page to redirect to a different href for each link?

If so the code would be:

Code:
<script>
$(".fb-share-button").click(function() {
   var redirectUrl = $(this).attr("data-href");
   $(location).attr('href', redirectUrl).delay("time in milliseconds");
});
</script>

To get the above working simply adjust the delay length and copy / paste into your html head.

PM me with any questions.
 
Last edited:
Solution with no jQuery:

Code:
<div class="fb-share-button" data-type="button" onclick="javascript: setTimeout(function(){location.href='http//MYDOMAINdotcom'}, 3000);">
</div>
 
Back
Top