带有iframe的弹出窗口显示JQM

时间:2014-09-16 10:21:20

标签: jquery-mobile iframe popup

我的弹出窗口以无政府状态打开,它应该在页面的中心打开并带有叠加层,但它会打开另一个页面,通过放置在具有白色背景的绝对位置。我希望它在demo jquery

中打开

Popup Iframe

这是一个外部弹出窗口

    <html>
    <body>
        <div data-role="popup" id="popIf" data-overlay-theme="b" data-theme="a" data-tolerance="15,15" class="ui-content"><iframe src="add.html" width="445" height="225" seamless=""></iframe></div>
        <div data-role="page" id="myfirstpage">

JS ==&gt;

$( document ).on( "pagecreate", function() {
// The window width and height are decreased by 30 to take the tolerance of 15 pixels at each side into account
function scale( width, height, padding, border ) {
    var scrWidth = $( window ).width() - 30,
        scrHeight = $( window ).height() - 30,
        ifrPadding = 2 * padding,
        ifrBorder = 2 * border,
        ifrWidth = width + ifrPadding + ifrBorder,
        ifrHeight = height + ifrPadding + ifrBorder,
        h, w;
    if ( ifrWidth < scrWidth && ifrHeight < scrHeight ) {
        w = ifrWidth;
        h = ifrHeight;
    } else if ( ( ifrWidth / scrWidth ) > ( ifrHeight / scrHeight ) ) {
        w = scrWidth;
        h = ( scrWidth / ifrWidth ) * ifrHeight;
    } else {
        h = scrHeight;
        w = ( scrHeight / ifrHeight ) * ifrWidth;
    }
    return {
        'width': w - ( ifrPadding + ifrBorder ),
        'height': h - ( ifrPadding + ifrBorder )
    };
};
$( ".ui-popup iframe" )
    .attr( "width", 0 )
    .attr( "height", "auto" );
$( "#popIf" ).on({
    popupbeforeposition: function() {
        // call our custom function scale() to get the width and height
        var size = scale( 445, 225, 15, 1 ),
            w = size.width,
            h = size.height;
        $( "#popIf iframe" )
            .attr( "width", w )
            .attr( "height", h );
    },
    popupafterclose: function() {
        $( "#popIf iframe" )
            .attr( "width", 0 )
            .attr( "height", 0 );
    }
});
});

1 个答案:

答案 0 :(得分:0)

您是否初始化外部弹出窗口?在pagecreate事件的开头添加此行:

$("#popIf").popup().enhanceWithin();

另外,你是如何推出弹出窗口的?确保你定位到窗口:

<a href="#popIf" data-rel="popup" class="ui-btn ui-corner-all ui-shadow ui-btn-inline" data-transition="pop" data-position-to="window">Basic Popup</a>
  

这是 DEMO