How do I get the link from a modal window? In case I want to send this link, the user clicking the link already open the modal. How do I do this?
How do I get the link from a modal window? In case I want to send this link, the user clicking the link already open the modal. How do I do this?
One option is to use hashtag
to inform that the client wants to open a modal
, eg:
www.sitedevendas.com/producto#comprar
In this way you would know that the client wants to open modal
buy and so you should parse in window.location.href
if #comprar
exists in . p>
$(document).ready(function() {
if(window.location.href.indexOf('#comprar') != -1) {
$('#comprar').modal('show');
}
});
Pass a parameter through the link:
example: http://dominio.com/nome_pagina_modal.html?par=open
In your application put this script (conditional operator (ternary)):
location.href.split("=").pop() == "open" ? $('#bannerformmodal').modal('show') : null;
location.href;
returns the URL of the current page split("=").pop();
takes the part after the = Operador Ternário
- If the condition location.href.split("=").pop() == "open"
is true, the operator will return the value $('#bannerformmodal').modal('show')
if not, it returns the value null;
.