To read the query string (GET) in a URL you can do a function like this:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
In this case if you have a url minhapagina.html?modal=true
then getParameterByName('modal)
var give true
.
This function fetched to Soen but you may not need something like this, if the URL that activates the modal does not have key / value pairs and only ?modal
or nothing; then a .indexOf()
is enough.
In this case you can use% location.search.indexOf('modal') != -1
that will give true ( true
) if the "modal" word exists in the ?xxxx
of the url.