Read query string with URI.js

// <script src="https://bowercdn.net/c/urijs-1.18.10/src/URI.min.js"></script>
 
// Page is: http://example.com/index.html?a=1&b=2
 
var parsedURI = URI.parse(document.location.href);
// { query: "a=1&b2=", protocol: "http", hostname: "example.com", ... }
 
var query = parsedURI.query;
// a=1&b=2
 
var parsedQuery = URI.parseQuery(query);
// { a: "1", b: "2" }
 
var a = parsedQuery.a;
// "1"
 
// In a single line:
a = URI.parseQuery(URI.parse(document.location.href).query).a;
// "1"

Comments

Popular posts from this blog

C# Record Serialization

Add timestamp to photo using ImageMagick

Read/write large blob to SQL Server from C#