homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Holding a Javascript Button
Have a new page appear up after holding a button down for 10 seconds
someone788

5+ Year Member



 
Msg#: 5091 posted 11:36 pm on Mar 1, 2006 (gmt 0)

Hey, I'm trying to figure out how to get a new page of my site to appear (in a different window) when a button is held down for 10 seconds. I'm pretty sure this can be done with javascript, just don't know how. Any thoughts? Thanks.

 

skinter

5+ Year Member



 
Msg#: 5091 posted 12:34 am on Mar 2, 2006 (gmt 0)

Start a for loop when your link (or button) is pressed, or the cursor hovers over it, then you can tell it to execute once your loop until it reaches the number. In this case, the number would be how many seconds.

There is probably a more efficient way, but this will work.

NOTE: for( int x = 0; x < 10; ++x ) won't work because 10 would be reached a lot quicker than in 10 seconds.

gph

10+ Year Member



 
Msg#: 5091 posted 12:54 am on Mar 2, 2006 (gmt 0)

you could use setTimeout


function chk(up){
if(up)clearTimeout(chk.timer);
else chk.timer=setTimeout('window.open("page.htm")',10000)
}

<input type="button" value="hold 10 sec" onmousedown="chk()" onmouseup="chk(1)">


someone788

5+ Year Member



 
Msg#: 5091 posted 4:09 am on Mar 2, 2006 (gmt 0)

Thanks, works great :)

One more question on a different idea using javascript. Is there a way to make it so that when you click a button (not hold down), it starts a timer counting down from 10, and when the timer hits 0, a link appears below (that can direct the user to another page). Or, alternativly, a link is already on the page, and just can't be used till the timer hits 0. Either of these will work, just looking for the easiest way to do it though.

gph

10+ Year Member



 
Msg#: 5091 posted 3:04 am on Mar 3, 2006 (gmt 0)

Is there a way to make it so that when you click a button (not hold down), it starts a timer counting down from 10, and when the timer hits 0, a link appears below (that can direct the user to another page).

Yes, set the link to display:none or visibility:hidden then use setTimeout onclick in the button to show the link.

someone788

5+ Year Member



 
Msg#: 5091 posted 7:25 pm on Mar 4, 2006 (gmt 0)

[quote]Yes, set the link to display:none or visibility:hidden then use setTimeout onclick in the button to show the link.[quote]
I understand what you are saying, but I'm not so good with javascript as to be able to actually write that. Could someone give me an example script please?

gph

10+ Year Member



 
Msg#: 5091 posted 7:45 pm on Mar 4, 2006 (gmt 0)

What you want to do isn't very hard to learn

[w3schools.com...]


function showLink(){
setTimeout('document.getElementById("link").style.display="inline"',10000)
}

<input type="button" value="showLink()" onclick="showLink()">

<a href="#" style="display:none" id="link">link</a>


someone788

5+ Year Member



 
Msg#: 5091 posted 9:40 pm on Mar 4, 2006 (gmt 0)

Thanks :)

I'll look over W3 again too (Have forgotten alot of javascript since the last time I had a refresher because I havn't been using it much).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved