/    Sign up×
Community /Pin to ProfileBookmark

[code=php]
<script type=”text/javascript”>

document.onkeyup = KeyCheck;

function KeyCheck(e)
{

var KeyID = (window.event) ? event.keyCode : e.keyCode;

if (KeyID == 27) //ESC
//close browser window
else
window.location = “<?php echo $_SERVER[‘SCRIPT_NAME’];?>/”+”<?php echo rand(100,999);?>”;

}

</script>
<?php
echo ‘<div align=”center”>Press any key</div>’;
?>
[/code]

This code will generate a random url, now I want if user press Esc or some times ( I set ) it will close the browser window, and I want to set a time delay between each times key pressed. Thank for helping.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@redfoxDec 07.2005 — i try editing you code to close the browser when you press esc, but can you explain more about time delay

<script language="text/javascript">

function KeyCheck(evt)

{

var evt = (evt) ? evt : ((event) ? event : null);

var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

if (evt.keyCode == 27) //ESC

//close browser window

window.close();

else

window.location = "<?php echo $_SERVER['SCRIPT_NAME'];?>/"+"<?php echo rand(100,999);?>";

}

document.onkeydown=KeyCheck;

</script>

<?php

echo '<div align="center">Press any key</div>';

?>
Copy linkTweet thisAlerts:
@chazzyDec 07.2005 — i'm a little curious as to why you're doing the pieces you're doing in php.
Copy linkTweet thisAlerts:
@redfoxDec 07.2005 — i was too, but that's what he wanted, hehehehehe
Copy linkTweet thisAlerts:
@Shishio_MakotoauthorDec 07.2005 — thank you very much.

to redfox: thank for your code, it helps me much. About time delay I meant when you press a key it will delay a little time before capture a next key you press although you press key rapidly ?

to chazzy: thank for your question. This is a part of my php page, so there a some php script in it ?

finally, sorry for my English ?
Copy linkTweet thisAlerts:
@redfoxDec 07.2005 — it's okay, about the timedelay, do you know how to use setTimeout in javascript, that would be the answer to you question , as you can set a time, how many seconds or milisecond, whatever, before it calls another function, example is

<html>

<script language="javascript">

function changeTextColor()

{

document.getElementById("testing").style.color="red";

setTimeout("changeTextColorBack()", 100);

}

function changeTextColorBack()

{

document.getElementById("testing").style.color="yellow";

setTimeout("changeTextColor()", 100);

}

</script>

<body onload="changeTextColor();">

<p align="justify" style="font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px" id="testing">Type you name and see if you look good today!!!<br/></p>

</body>

</html>

just cut and paste, and experiment on the setTimeOut, change the number in the functio which is 100, try placing larger number
×

Success!

Help @Shishio_Makoto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...