• Home
  • Trace mobile number (From India)
  • Entertainment
  • SiteMap
  • Home
  • ASP.NET
  • C#
  • BLOGGING
  • SQL SERVER
  • FACEBOOK
  • Entertainment
Showing posts with label Javascript Code Snippets. Show all posts

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.


   <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.


<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:
Older Posts Home

Most Read

  • How to Capitalize the First Letter of All Words in a string in C# ?
  • keyboard shortcuts For Windows
  • List Of Best Free WordPress Plugins : 2012
  • Read Write XML Data-Read Write XML File Using C#, VB.NET In Asp.Net
  • How to Shake Internet Explorer - Javascript Code
  • How to Choose a Nice Topic for your Blog .
  • Free Search Engine Submission List ,search engine optimization
  • Number validation in Textbox of ASP.NET Using Regular Expression validator
  • Javascript:Percentage Gain Javascript Calculator
  • .Net Interview Questions and Answers on OOPS | OOPS Frequently Asked Questions
Google
Custom Search Bloggers - Meet Millions of Bloggers

Join Us On FaceBook

  • Recent Posts
  • Comments

All Topics

  • ▼  2014 (10)
    • ▼  January (10)
      • ASP.NET Interview Question : difference between ge...
      • Dot Net Framework:What is the .NET Framework?
      • Dot NET Framework - .NET Framework Interview Quest...
      • What is the differences between MVC2,MVC3 and MVC4...
      • Is try catch is using a good coding (exception han...
      • What is the use of Just - In - Time (JIT)?
      • What is GUID , why we use it?,how to create a GUID
      • How to Rename database table column in sqlserver
      • How to Rename Database in sqlserver
      • Asp.net Example Calendar Control
  • ►  2013 (14)
    • ►  October (1)
    • ►  April (2)
    • ►  March (11)
  • ►  2012 (142)
    • ►  December (25)
    • ►  October (1)
    • ►  September (9)
    • ►  August (2)
    • ►  July (7)
    • ►  June (2)
    • ►  April (5)
    • ►  March (27)
    • ►  February (27)
    • ►  January (37)
  • ►  2011 (23)
    • ►  December (3)
    • ►  November (6)
    • ►  October (12)
    • ►  September (2)
  • ►  2009 (1)
    • ►  June (1)

Tips & Tricks

  • What is good One Blog and Many Categories, or Many Blogs with One Categories?
  • Adding Twitter tweet button to each Blogger posts.
  • How to Choose a Nice Topic for your Blog .
  • Embedding YouTube Videos ,movie in your blog
  • Facebook iFrame Apps – Getting Rid of Scrollbars
  • Facebook Analytics:How to Set Up Your Website or Blog with Facebook Insights for Domains
  • How To Add Perfect Share Box to Blogger
  • Blogger Free Images Hosting Tip,Free unlimited bandwidth image hosting for Blogger blogs
  • Add “Link to this post” codes below Each blogger posts
  • Free Search Engine Submission List ,search engine optimization
  • Adsense Tips for Maximum CTR
  • List Of Best Free WordPress Plugins : 2012
2012 tectopix. All rights reserved.
Designed by tectopix