There is no sleep() /wait() function in Javascript. The setTimeout() is not exactly a sleep() /wait() function as it behaves like creating another thread for the scheduled task.
By Google , i got a manual sleep() /wait() function. Try the following code. Continue reading Javascript – Sleep Function →
In PHP , we can use the header() function to redirect the URL .
In HTML , we can use the meta tag to redirect the URL .
For more information, visit PHP/HTML – Redirect URL in Seconds
But sometimes, we want the redirection starts after the HTML body is loaded. This can be done by Javascript . Continue reading Javascript – HTML Redirect →
The following Javascript function will redirect you to the previous URL when it is called.
function goToPreviousPage() {
history.go(-1)
}
Add a return button to your HTML page as follow.
<input type="button" name="returnButton" value="Return" onclick="history.go(-1);"/>
Done =)
Reference: Back to previous page
Previous post: Javacript – Schedule a Function call by setTimeout()
If the delayed function has input parameters , setTimeout() would fail when you simply add the parameters in the setTimeout() call.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/* The call will fail and the alert box will display immediately */
setTimeout(delayedAlert("Hi Eureka!"), 3000);
});
function delayedAlert(str) {
alert(str);
}
</script>
Continue reading Javascript – Passing Parameters for the Function in setTimeout() →
In Javascript , you could schedule a function call using the setTimeout() .
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setTimeout(delayedAlert, 3000);
});
function delayedAlert() {
alert("Hello Eureka!");
}
</script>
</head>
<body>
<h1>Eureka!</h1>
</body>
</html>
Continue reading jQuery & Javascript – Schedule a Function call by setTimeout() →
Convert String to Number using parseFloat() or parseInt()
/* parseFloat() */
parseFloat('1.45kg') // 1.45
parseFloat('77.3') // 77.3
parseFloat('077.3') // 77.3
parseFloat('0x77.3') // 0
parseFloat('.3') // 0.3
parseFloat('0.1e6') // 100000
/* parseInt() */
parseInt('123.45') // 123
parseInt('77') // 77
parseInt('077',10) // 77
parseInt('77',8) // 63 (= 7 + 7*8)
parseInt('077') // 63 (= 7 + 7*8)
parseInt('77',16) // 119 (= 7 + 7*16)
parseInt('0x77') // 119 (= 7 + 7*16)
parseInt('099') // 0 (9 is not an octal digit)
parseInt('99',8) // 0 or NaN, depending on the platform
parseInt('0.1e6') // 0
parseInt('ZZ',36) // 1295 (= 35 + 35*36)
Continue reading Javascript – Convert Number to String and Vice Versa →
In Javascript , the following code will open a link in a new tag.
window.open('url');
I want the browser prompt me a download dialogue box after i click a link and finally redirect me to a thank you page. The following code could make it.
Continue reading Javascript – Open a link in new window →
Submitting a HTML form in Javascript can be done by just one line.
Continue reading Javascript – HTML Form Submission →
Ajax is very popular in websites nowadays. You can make a simple Ajax POST Request with only 2 files as shown as below.
Continue reading Ajax – Simple Ajax POST Request →
As requested by Andrew . Here is an example on creating a Drop Down Menu using Javascript and CSS .
Reference: Simple Drop-Down Menu v2.0
Continue reading Javascript – Drop Down Menu →
Posts navigation
Dream BIG and go for it =)