I
I
Ivan2020-01-22 14:00:15
PHP
Ivan, 2020-01-22 14:00:15

How do I get the url to a page with a popup window already open?

Good afternoon!
On the site, it is necessary to implement the ability to transfer the URL to another user (by email, in chat, etc.) in such a way that when clicking on this link, the desired modal is opened, there may be several of them on the page. Site settings PHP back Bootstrap4 front. I would also be extremely grateful if someone knows sites with live examples of such an implementation.
My idea is to pass the id of the modal and the show parameter in the url itself,

$('btn-primary').click(function () {
  $(location).attr('href', 'website.com/page-with-popups.html?idpopup=1&popup=show')
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-01-22
@Aetae

Read the received parameters from the address bar and open the modal, something like this:

$(document).ready(function () {
  var searchParams = new URLSearchParams(location.search.slice(1));
  if(searchParams.get('popup') === 'show') {
    $("#myModal-" +  searchParams.get('idpopup')).modal();
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question