Reputation: 1418
Here is an example of what I need help with: http://www.arbutusroofing.com/roofing-services/
When the user clicks on “READ MORE” (under each subject or category) and the light grey box pops up with more information, I want it to automatically redirect to another page in 10 seconds.
I know how to redirect to a different page when an actual link is clicked, but not with certain events like this.
Here is some example of the code:
<h6 id="displayText" style="margin-top: 0px; cursor: pointer;">
<u>READ MORE</u> ABOUT FLAT ROOFING
</h6>
I'm trying to redirect to a different page after 10 seconds when the id "displaytext" is clicked on.
Also, here is the code for the toggle text if you were wondering:
<script type="text/javascript">
$(document).ready(function() {
$("div#toggleText").hide();
$("h6#displayText").click(function(){
$(this).toggleClass("active");
$(this).next("div#toggleText").slideToggle();
});
});
</script>
Upvotes: 0
Views: 14803
Reputation: 1520
You JS code:
function OpenNewTab(id){
setTimeout(function(){ window.location.href = "http://yourlinkhere/'+id+'"; }, 10000);
}
HTML:
<div onclick="OpenNewTab(1)">Readmore</div> // here 1 SHOULD BE UNIQUE ID AS PER RECORDS
Upvotes: 4
Reputation: 170
I think you can use settimeout function. Eg:
setTimeout("location.href = 'http://insert-target-url';",1500);
setTimeout need two arguments. First is the action that will be executed. It can be simple redirect command, or event a function. The second one is the delay in milliseconds.
Hope this helps you.
Upvotes: 0
Reputation: 2464
You can execute code with a delay using the setTimout function. An example of linking to google.com 10 seconds after the 'click' div is clicked:
<div onclick='setTimeout(function(){window.location = "http://www.google.com"}, 10000)'>Click</div>
Upvotes: 0
Reputation: 802
You're probably looking for the javascript function setTimeout.
setTimeout(function(){ window.location.href = "http://somehwereblahblah"; }, 10000);
Upvotes: 0