0

OK So I need to detect if someone is using mobile and then politely ask them to rotate the screen so that it is a landscape window, not a vertical one.

I found this answer for detecting a mobile browser.

Using Bootstrap, I would like to make a modal appear for to tell them to rotate the screen.

I also found this from the Bootstrap JavaScript guides:

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
      Launch demo modal
</button>

As you can see they use data-toggle="modal" data-target="#myModal" to call forth the modal. How would I go about implementing that so it runs when a Javascript value is returned?

Something like

if ( mobile == 1 ) {
    // open modal
else {
   // ignore modal (do nothing)
}

would suffice for the detection, but how would I go about the //open modal part?

jQuery can be used as well, if that helps anyone (removes some restrictions).

Thanks!

Community
  • 1
  • 1
Brennan Macaig
  • 183
  • 1
  • 1
  • 8

1 Answers1

1

Examples of how to interact with Bootstrap modals in JavaScript can be found at http://getbootstrap.com/javascript/#modals. In short, it looks like you can programmatically call $('#myModal').modal(options) on an element to activate it as a modal dialog.

Sam
  • 3,670
  • 1
  • 11
  • 27