Assign link to a modal bootstrap window

Asked

Viewed 1,056 times

0

How do I link to a modal window? In case I want to send this link, the user by clicking on the link already open direct the modal. How do I do that?

2 answers

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(); picks up 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 no, it returns the value null;.
  • Or rather, you don’t need to convert Location.href into string, because it is already string. You can delete a line there.

  • var parametro = (Location.href). split("="). pop();

  • Aha.. put in the functional example for us to see

  • @Fucking posted on the server

  • Only the.. rsss.. was much better in my opinion

  • 20 lines left only 1 rsrs

Show 1 more comment

0


Possible solution

One option is to use hashtag to inform that the client wants to open a modal, example:

www.sitedevendas.com/product#buy

That way you would know that the client wants to open the modal buy and so you should analyze in window.location.href if there is #comprar in that string.


Example

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

Browser other questions tagged

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