Assign link to a modal bootstrap window

0

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?

    
asked by anonymous 29.11.2017 / 20:57

2 answers

0

Possible solution

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>

Example

$(document).ready(function() {
  if(window.location.href.indexOf('#comprar') != -1) {
    $('#comprar').modal('show');
  }
});
    
29.11.2017 / 22:45
2

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; .
29.11.2017 / 22:57