Is there a way to get a query string from JavaScript? Should I use jQuery or something like that? Or is it possible only with JavaScript?
javascript url
You can only use pure JavaScript.
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
How to write
// query string: ?foo=lorem&bar=&baz
var foo = getParameterByName('foo'); // "lorem"
bar bar = getParameterByName('bar'); // " (value is empty)
varbaz = getParameterByName('baz'); // "" (no value)
var qux = getParameterByName('qux'); // null
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.