Loction: Location property is a window object property.
It is representing current web browser displaying web page address.
Eg:
<html>
<head>
<script type = "text/javascript">
function currenturl()
{
alert(window.location)
}
function changeurl()
{
window.location = "http://www.gmail.com"
}
</script>
</head>
<body>
<input type = "button" value = "current url" onclick= "curranturl()">
<input type = "button" value = "Change url" onclick= "changeurl()">
</body>
</html>
Output:
document object: It is a java script predefined object, it is representing the html document.
This object can access the html document by using its properties.
Eg: To display title of the web page:
title: It is a property of document object.
Title property is representing the title of the html web page.
Using this property we can access the title tag content.
Synatx: document.title
<html>
<body>
<script type = "text/javscript">
alert("This web page page title is " +document.title)
</script>
</body>
</html>
Output:
Eg: To display current web page url:
URL: It is a property of document object.
This property is representing the current html document or html web page url.
Syntax: document.URL
<html>
<head>
<title> Microsoft Windows </title>
</head>
<body>
<script type = "text/javascript">
alert("This web page url " +document.URL)
</script>
</body>
</html>
Output:
onmousedown: This event will fire when user will click mouse buttons.
event object: event is a java script pre-define object, it is holding complete information about the current raising event or firing event or executing event with some of properties.
event.button: Here button is a property of event this button property is representing the mouse buttons.
If user will click left mouse button this button property is representing with '1' value, if user will press right mouse button this button representing the '2' value.
Eg: For onmousedown event:
<html>
<head>
<script type = "text/javscript">
function whichbutton(event)
{
if (event.button == 1)
alert(your are pressed left mouse button)
else
alert(your pressed right mouse button)
}
</script>
</head>
<body onmousedown= "whichbutton(event)">
</body>
</html>
Output: