How can I run javascript code just after page load, when page is loaded, it trigger, and when I go to another page it also trigger another piece of code for that page, how can I do it ?
2 Answers
You can try
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function codeAddress() {
alert('ok');
}
window.onload = codeAddress;
</script>
</head>
<body>
</body>
</html>
Click here http://jsfiddle.net/NEfR2/
Comments
document.ready() is a jQuery event. JQuery’s document.ready() method gets called as soon as the DOM is ready (which means that the browser has parsed the HTML and built the DOM tree). This allows you to run code as soon as the document is ready to be manipulated.
For example, if a browser supports the DOMContentLoaded event (as many non-IE browsers do), then it will fire on that event. However, IE can’t safely fire until the document’s readyState reaches “complete”, which is typically later.
You can find more info here (of course, this requires jQuery to be loaded)
window.onload = function() { // do something }$(document).ready()javascript page load. Please show some efort before posting rudimantary questions here