admin管理员组

文章数量:1288055

I have a link like this

<a href='/path/to/popup.html' data-role="button">COME HERE </a>

I want to open the popup.html file as a jquery popup. And I cant have it inside the current page as a <div> with an id. I must have it out side the current file.

And I cant use dialog's as it reloads the current page. Any idea on how to do it?

Inside the popup.html I am using just a single header.

Or any methods through which I can avoid the page being reloaded when dialog is closed?

I have a link like this

<a href='/path/to/popup.html' data-role="button">COME HERE </a>

I want to open the popup.html file as a jquery popup. And I cant have it inside the current page as a <div> with an id. I must have it out side the current file.

And I cant use dialog's as it reloads the current page. Any idea on how to do it?

Inside the popup.html I am using just a single header.

Or any methods through which I can avoid the page being reloaded when dialog is closed?
Share Improve this question asked Feb 8, 2014 at 0:55 user3283104user3283104 4163 gold badges5 silver badges14 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4

Use .load() to load popup.html into a placeholder (i.e <div id="PopupPH">). This placeholder can be placed either inside data-role="page or outside it, depending on jQuery Mobile version you are using.

Moreover, in popup.html, you need to change data-role=page" to data-role="popup in order to treat it as a popup not a page.

jQuery Mobile 1.4

Insert placeholder inside body tag or data-role="page" and load popup.html.

<body>
  <div data-role="page">
  </div>
  <div id="PopupPH">
    <!-- placeholder for popup -->
  </div>
</body>

Or

<body>
  <div data-role="page">
    <div id="PopupPH">
      <!-- placeholder for popup -->
    </div>
  </div>
</body>

Load popup.html into placeholder

$("#PopupPH").load("popup.html");

Inside popup.html popup div, add JS to create, open and remove popup once it's closed.

<div data-role="popup">
  <!-- contents -->
  <script>
    $("[data-role=popup]").enhanceWithin().popup({
        afterclose: function () {
            $(this).remove();
        }
    }).popup("open");
  </script>
</div>

jQuery Mobile 1.3 and below

Do the same as above, except for popup placeholder should be inside data-role="page", because jQM 1.3 doesn't support external popup. Also, replace .enhanceWithin() with .trigger("create").

Using the frames & popups in jQuery mobile, you can simply include an iframe inside, although dialogs are still probably your better bet. (Especially as a click outside the popup.. kills it)

<div class="hidden">
     <div data-role="popup" id="externalpage">
         <iframe src="http://www.bbc." 
                 width="480" 
                 height="320" 
                 seamless>
          </iframe>
     </div>
</div>    

<a href='#externalpage' 
   data-rel="popup"  
   data-role="button">COME HERE</a>

<script>
$(document).on("pageinit", function() {    
    $( "#externalpage" ).on({
        popupbeforeposition: function( event, ui ) {  
            console.log( event.target );
        }
    });
});
</script>

Demo: http://jsfiddle/tcS8B/ jQuery Mobile Dialogs don't refresh the page I don't think, it simply masks it with a new background for focused attention.

Try

<a href="google." rel="external">Test</a>

本文标签: javascriptHow to open an external html page as a popup in jquery mobileStack Overflow