To read the query string (GET) in a URL you can make 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) give away true.
This function I went to get from Soen but you may not even need something like this, if the url that activates the modal has no key/value pairs and only ?modal or nothing; then a .indexOf() suffice.
In this case you can use location.search.indexOf('modal') != -1 that will give real (true) if the word "modal" exists in ?xxxx of the url.
This external URL will be entered by someone else remotely?
– Tobias Mesquita
Can you explain "call this modal from an external page"? so the page has the possibility to display a modal but only does it if the URL asks it? type Query string?
minhapagina.html?modal=true-> opens andminhapagina.html-> won’t open?– Sergio
is an external link, it passes a method
GETand with it show the modal– wwwjsw
So you want to read the querystring in JS to see if the modal should open? That’s it?
– Sergio
@Yes, yes, that’s right
– wwwjsw
ok, I’ll give you an answer but you can give one more indication: what does that url look like when you should call the modal? has some key to the modal?
– Sergio