Wednesday, 20 December 2017

Get url parameter jquery Or How to Get Query String Values In js

itemprop="text">

I have seen lots of jQuery examples
where parameter size and name are unknown. My url is only going to ever have 1
string:



http://example.com?sent=yes


I
just want to
detect:





  1. Does
    sent exist?

  2. Is it equal to
    "yes"?


itemprop="text">
class="normal">Answer



Best
solution href="http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html"
rel="noreferrer">here.



var
getUrlParameter = function getUrlParameter(sParam) {
var sPageURL =
window.location.search.substring(1),

sURLVariables =
sPageURL.split('&'),
sParameterName,
i;


for (i = 0; i < sURLVariables.length; i++) {
sParameterName =
sURLVariables[i].split('=');

if (sParameterName[0] === sParam)
{
return sParameterName[1] === undefined ? true :
decodeURIComponent(sParameterName[1]);
}


}
};


And
this is how you can use this function assuming the URL is, />http://dummy.com/?technology=jquery&blog=jquerybyexample.



var tech =
getUrlParameter('technology');
var blog =
getUrlParameter('blog');


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...