
The Geolocation API provides a method to locate the user’s exact position. This is useful in a number of ways ranging from providing a user with location specific information to providing route navigation.Internet Explorer 9, Firefox, Chrome, Safari and Opera support Geolocation.
A number of different sources are used to attempt to obtain the user’s location, and each has their own varying degree of accuracy. A desktop browser is likely to use WiFi (accurate to 20m) or IP Geolocation which is only accurate to the city level and can provide false positives. Mobile devices tend to use triangulation techniques such as GPS (accurate to 10m and only works outside), WiFi and GSM/CDMA cell IDs (accurate to 1000m).
Use the getCurrentPosition() method to get the user's position.
The example below is a simple Geolocation example returning the latitude and longitude of the user's position:
<script>
var MyLoc=document.getElementById("demo");
function getUserLocation()
{
if (navigator.geolocation) //This will check if browser support geolocation.
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
MyLoc.innerHTML="Geolocation is not supported by this browser.";
}
}
function showPosition(position)
{
MyLoc.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
The above function first Check if Geolocation is supported by browser If supported, run the getCurrentPosition() method. If Geolocation is supported by browser, display a message to the user .If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter ( showPosition ) and The showPosition() function gets the displays the Latitude and Longitude.
Displaying the Result in a Map
To display the result in a map, you need access to a map service that can use latitude and longitude, like Google Maps. Change the showPosition method like this .
<script>
var MyLoc=document.getElementById("demo");
function getUserLocation()
{
if (navigator.geolocation) //This will check if browser support geolocation.
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
MyLoc.innerHTML="Geolocation is not supported by this browser.";
}
}
function showPosition(position)
{
var latlon=position.coords.latitude+","+position.coords.longitude;
var img_url="http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML="<img src='"+img_url+"'>";
}
</script>
This script will display location in map.
Email Validation: Cross browser Email Validation in JS. JavaScript for Email Address Validation with explanation of the code.The script on this page has been updated to deal with cross-browser issues. Learn how to validate a users email address using Javascript.
Using Regular Expressions is probably the best way. Here's is an function Which will return true if Email is a Valid email and false if email is not valid .
<script>
function
validateEmail(email) {
var regstring
= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return regstring.test(email);
}
</script>
But keep in mind that one should not rely only upon JavaScript validation. JavaScript can easily be disabled. This should be validated on the server side as well.
Textbox empty check using javascript,empty textbox validation with javascript ,JavaScript tutorial validate form: Textboxes,Client Side Validation using JavaScript for textbox empty check . how to write javascript alert message for empty textbox , javascript validation to a textfield to check for null.
If you have a textbox and you want to check that the box must not be null using javascript. the below javascript code will help you.
JavaScript Example Code
<script>
function
checknull()
{
if(document.getElementById("txttext").value=="")
{
alert("Please
enter value.");
return false;
}
}
</script>
You just call this function on Blur to event to check textbox is empty or having value.
onblur="
checknull() ;" -- add this to text box property Like below
<asp:TextBox ID="txttext" runat="server" Text="" onblur=" checknull();"></asp:TextBox>
All The Best !!!
Add a moving title on your page,Magic title for weblogs or any pages on the internet
Some time you want to add a moving title on your page A title for the page which is always changing and moving so nice.The below script will make your page title moving.
Add the below javascript code within your <head> and </head> tag.
If you want to change the color of the scrollbar of your choice then this code is for you it will make your web pages scrollbar colorful and make your website fancy.
Note:Paste below code within <head> and </head> tag.
Note:Paste below code within <head> and </head> tag.
<style>
BODY {
SCROLLBAR-FACE-COLOR: red; SCROLLBAR-HIGHLIGHT-COLOR:
gray;
SCROLLBAR-SHADOW-COLOR: black; SCROLLBAR-ARROW-COLOR:
gray;
SCROLLBAR-TRACK-COLOR: black; SCROLLBAR-DARKSHADOW-COLOR:
red
}
</style>
If you want to show some message box or a alert window when user at the first open your page then the below Javascript code is for you.
The below Javascript code will open an alert box when user comes first time on your webpage.
Code:
<script language="javascript" type="text/javascript">
alert("You are Welcome to my site")
</script>
Just paste the below Javascript code within <head> and </head> tags on your webpage as shown below.And change message according to your need.
The below Javascript code will open an alert box when user comes first time on your webpage.
Code:
<script language="javascript" type="text/javascript">
alert("You are Welcome to my site")
</script>
Just paste the below Javascript code within <head> and </head> tags on your webpage as shown below.And change message according to your need.
<html>
<head>
<script language="javascript" type="text/javascript">
alert("You are Welcome to my site")
</script>
</head>
</html>
This below JavaScript code will enable you to place a button on your website that, when clicked on, will make your web site your visitors home page.
<INPUT TYPE="button"
VALUE="Make This
page Your Home Page" onClick="this.style.behavior='url(#default#homepage)';
this.setHomePage('http:// www.usetricks.com');">
Display: