[英]Enlarge iframe without reloading html contents using only css
I haven't done web development long enough to know the constraints of it all but I have a need to display an iframe in a larger window without reloading the html inside it. 我还没有足够长的时间进行网络开发,以了解所有这些限制,但是我需要在更大的窗口中显示一个iframe,而无需重新加载其中的html。 I would like to use javascript/css only, I'm not really sure where to begin with this.
我只想使用javascript / css,我不太确定从哪里开始。
Currently I have an iframe click event that when clicked will load a jquery-ui dialog with the same html from the iframe.. but the page inside the dialog loads all the javascript etc I had ran previously in the iframe. 当前,我有一个iframe click事件,单击该事件会从iframe中加载具有相同html的jquery-ui对话框..但对话框中的页面会加载我之前在iframe中运行的所有javascript等。
header 标头
<!-- jquery -->
<script type="text/javascript" src="./js/jquery-1.11.1.min.js"></script>
<!-- html dialog -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
javascript javascript
<script>
$(document).ready(function() {
var $dialog = $('#dialog').dialog({
autoOpen: false,
modal: true,
height: 850,
width: 900,
title: "Some title"
});
$('.iframe-class').load(function(){
$(this).contents().find("body").on('click', function(event) {
//$( "#dialog" ).dialog( "open" );
var page = "http://localhost/test/graph.html";
var $dialog = $('#dialog')
.html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>');
$dialog.dialog('open');
});
});
});
</script>
html html
<div id="frametest">
<iframe class="iframe-class" scrolling="no" src="/test/graph.html?a=1">
<p>Your browser does not support iframes.</p>
</iframe>
<div id="dialog"></div>
</div>
thank you for your help! 谢谢您的帮助!
Here is a simple fiddle: http://jsfiddle.net/d2Lmtqce/1/ 这是一个简单的小提琴: http : //jsfiddle.net/d2Lmtqce/1/
function putTheFrameInDialog()
{
$(function(){
$('#iframeContainer').dialog();
});
}
Basically, i've just created a container for your iFrame. 基本上,我刚刚为iFrame创建了一个容器。 This container is used by jQuery UI
dialog()
method. jQuery UI
dialog()
方法使用此容器。
<button onclick="putTheFrameInDialog();" value="Hey!">Hey!</button>
<div id="iframeContainer">
<iframe src="http://www.senado.gov.br/" id="myFrame"/>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.