How to Get Query strings and Hashvalue Parameters
In this tutorial, We are going to show how to retrieve URL value with the help of JavaScript and JQuery. in this case, Generally we get the value from browser URL with the help of some server side scripting languages like: - ASP, PHP and C Sharpe(#).So here we are telling to all of you how to get value from URL with help of JavaScript. It is quite easy to use this in your project code. if you have good hand on programming practice.
1). How to GET current URL of page.
A Very simple code, by that you can easily store the Current page URL in a JavaScript Variable.
// How to Retrieve Current URL Path var url = document.URL;
2). How to GET current Root URL of page.
In this simple Syntax code, We can get the current URL value into a variable.
// How to Retrieve Root URL of Current Page var rootURL = location.protocol + '//' + location.host;
3). How to Redirect page using JavaScript
In this Syntax Code, You can also use JQuery for redirecting the page.
// How to Redirect - Insert required URL window.location.href = "http://estuffcage.com/"; or "http://estuffcage.blogspot.in/";
4). How to get Parameter in Querystring of current page
sometime we send multiple parameters with value in browser URL and then we receive it into the different variables. so all this stuff we can also do with the help of Querystring. In this way we have to parse each parameter and store the array value as a variable:
var vars = [], hashvalue;
var query = document.URL.split('?')[1];
if(query != undefined)
{
query = query.split('&');
for(var i = 0; i < query.length; i++)
{
hashvalue = query[i].split('=');
vars.push(hashvalue[1]);
vars[hashvalue[0]] = hashvalue[1];
}
}
For using the parameter value by accessing the parameter name. like: -
if our Browser URL contain "?x=4&y=7&z=9" with this help we can use the value for "x" using.
// Will alert the value of parameter x
alert(vars['x']);
5). How to Get the URL Hash Parameter
Retrieve a hash parameter and store in a variable:
// How to Get # parameter from the URL in Browser.
var param = document.URL.split('#')[1];
Still if you are unable to use this code then feel free to contact me through contact form and if you have any query regarding Adsense or Blogging. then you can also share with us.
Thanks, Don't Forget to give feedback for this post.
You Might Also Read : -
- How to Send Bulk Emails in java Technology.
- How to Check all Checkboxes by clicking one checkbox.
- How to Completely Disable cache for PHP project.
- How to Send data using Ajax and JavaScript into database.
- Dynamically Add Input fields into the form using JQuery.
- Magento Issues While Installing a New Installation or Theme.
0 comments :
Post a Comment