Javascript
Changing URL in Address Bar using Javascript
By using this we can change the url of the page in address bar without reloading the page. This can be used for ajax calls that need to change url without reloading the page.
window.history.pushState("string", "Title", "/new-url");
window.history.replaceState("string", "Title", "/another-new-url");
..
How to set title dynamicaly
Here is a simple example to set title for an image by jquery.
HTML Code
<li><a href="home.html"><img src="images/home.jpg" ></a></li>
<li><a href="contact.html"><img src="images/contact.jpg"></a></li>
Javascript Code
$(document).ready(function(){
$('.menu li').mouseover( function(){
var src = $(this).find('a').attr('href');
..
Get days between two given dates
How to find number of days between two dates
By using the below code snippet you can get number of days between two given dates. here in below javascript code I have passed date1 and date2 as two different dates fro which we have to find the number of days between ..
Validate ip address using javascript
Mostly we user to validate ipaddress and email using regula exression from server side, it is also not a very bad idea to validate IP Address using simple javascript. Below is the javascript code to validate IPAddress.
function ValidateIPaddress(inputText)
{
var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if(inputText.value.match(ipformat))
{
document.form1.text1.focus();
return true;
} ..
Jquery div tag into href
HTML code
<div class='css_classname'> < a href='index.php'> Index </a> </div>
<div class='css_classname'> < a href='linux1.php'> Linux 1 </a> </div>
<div class='css_classname'> < a href='linux2.php'> Linux 2 </a> </div>
Css code
<style>
.css_classname { border: 3px solid #F3D1B6;
border-radius: 10px 10px 10px 10px;
color: #E8C2AF;
font: bold 11px/20px Tahoma,Geneva,sans-serif;
padding: 0 7px;
}
</style>
Inside javascript or jquery
<script>
$('.css_classname').click(function() {
window.location.href = $(this).find('a').attr('href');
});
</script>
You ..
Javascript resize orientationchange
Bind the "resize orientationchange" function to the window, on change get "cliendWidth" and store it in a variable.
How to get window size on resize or orientation change using javascript
$(window).bind('resize orientationchange', function() {
var ww = document.body.clientWidth;
alert(ww);
});
..
Jquery validation using php n ajax
How to check if an email is already registered or not?
Check if an email is already registered in jquery validation. For this we use remote attribute in jquery validation plugin
$(function(){
$("form.signupform").validate({
rules:{
email:{
required:true,
email:true,
remote:{
url:"email-not-registered.php",
type:"post"
..
Detect users screen size and screen resolution
Many people use different hardware/pc for accessing online applications. In this growing trend web application are presented for web users depending upon their screen size, By using the below coed you can find the screen size od the device used by the user.
<?php
if(isset($_COOKIE["deviceResolution"])) {
$urScreenRes ..
Auto nofollow attribute for links
How to add Auto nofollow attribute for links
You can add nofollow urls via javascript using below scripts.
<script type=\"text/javascript\">
jQuery(document).ready(function(){
jQuery(\'a[href*=\"http://\"]:not([href*=\"http://www.techbluff.com\"])\').attr(\'rel\',\'nofollow\');
jQuery(\'a[href*=\"https://\"]:not([href*=\"https://www.techbluff.com\"])\').attr(\'rel\',\'nofollow\');
});
</script>
..
Fetch array values in javascript from php
1. Create php array
<?php
$arrPhp=array("1","2","3","4","5');
?>
2. Create javascript array
<script>
var arrJava=new Array();
</script>
3. Now assign php array value to javascript array value
<script>
<?php
for($i=0;$i<count($arrPhp);$i++)
echo "arrJava[".$i."]=".$arrPhp[$i].";";
?>
alert(arrJava);
</script>
..
Create draggable Div - jQuery
1. First insert jquery file in header field.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
2. create a div which is used to drag.
<div id="draggable"></div>
3. Now, write the draggable function in script tag.
$(function() {
$( "#draggable" ).draggable();
});
4. Now div is draggable anywhere.
..
How to get lattitude n longitude from google maps
How to get lattitude n longitude from google maps?
Its easy to get lattitude n longitude from google maps, Its not required to write your own code or build you own DB to get lattitude n longitude from google maps using below code.
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=AIzaSyB6HHtXKJOnGVmQLm6cr5oXLFu-vJK8aSs" type="text/javascript">
</script>
<script ..
How to calculate log of base x
How to calculate log of base x value using javascript?
The below code will help you to calculate log of x values using javascript.
Base 10
function log10(val)
{
return Math.log(val) / Math.LN10;
}
All base of Log value
Math.log = (function()
{
var log = Math.log;
return function(n, base) ..
How to calculate degree value
How to calculate degree value using javascript?
Javascript can be used to calculate trigonometric value or degree. While calculating the degree, the degree value must be divide by 57.2957795130823 and call Math trigonometric functions.
Example:
var deg = 45; // degree value
var conv = 57.2957795130823; // Conversion value
Math.sin(deg ..
Algorithm to calculate polygon area
Algorithm to calculate polygon area in Javascript
function polygonArea(X, Y, numPoints)
{
area = 0; // Accumulates area in the loop
j = numPoints-1; // The last vertex is the 'previous' one to the first
for (i=0; i<numPoints; i++)
{ area = area + (X[j]+X[i]) * (Y[j]-Y[i]); ..