Wednesday, February 15, 2012

jQuery display url and redirect functions

My own redirect function and get or display site's url. This is to simplify your code by using functions.
function redirectURL(url){
    window.location.href=url;
}

How to use:
jQuery(document).ready(function(){
if(condition){
      redirectURL("http://www.google.com");
}
else{
      redirectURL("http://www.yahoo.com");
});


function getURL(){
    return window.location.href;
}

How to use:

jQuery(document).ready(function(){
  var siteURL=getURL();
  alert(siteURL);
});

No comments:

Post a Comment