Calling modal via url

Asked

Viewed 985 times

0

I have a page on which there is a Modal registration, I have to call this modal from an external page, preferably by url, I would like to know if it is possible and if you can show me the way

OBS: THE Modal cannot be enabled directly on the page, and this page uses the Bootstrap to generate the Modai's.

  • This external URL will be entered by someone else remotely?

  • 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 and minhapagina.html -> won’t open?

  • is an external link, it passes a method GET and with it show the modal

  • So you want to read the querystring in JS to see if the modal should open? That’s it?

  • @Yes, yes, that’s right

  • 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?

Show 1 more comment

1 answer

1


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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.