Johan Rheeder
Johan Rheeder

Reputation: 319

Link to a modal on another page twitter bootstrap

I am looking for a way to link to a modal on another page (building a nav system). So essentialy I want to link to the modal, which in turn will jump to the corresponding page (for this example we will use invoice.php) and then have the modal popup.

Now I have tried:

<li><a href="<?php echo site_url('site/invoice#myModal');?>" data-toggle="modal" title="">Open order screen</a></li> 

as well as

<li><a href="<?php echo site_url('site/invoice');?>" data-toggle="modal" data-target="#myModal" title="">Open order screen</a></li> 

This works on the invoice.php page, but this does nothing from a page where the modal doesn't exist. (i.e. from index.php). So how would I approach getting #myModal to open by link to it from an external page?

Regards,

Upvotes: 1

Views: 4903

Answers (1)

Johan Rheeder
Johan Rheeder

Reputation: 319

Ok So I have managed to resolve this (quite easily in the end). Helps if you actually think things through. SO the solution is as follows

On Index.php

<li><a href="<?php echo site_url('site/invoice#mdx');?>" data-toggle="modal" title="">Open order screen</a></li> 

On invoice.php

Add this to the end of the document

<script>
   $(document).ready(function () {
      var hash = window.location.hash;
      if (hash == "#mdx") {
         $('#myModal').modal();
      }
   });
</script>

Upvotes: 5

Related Questions