iframe大小随浏览器窗口大小而改变
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>iframe</title>
</head>
<body>
<iframe id="mainiframe" style="background-color:red"></iframe>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
window.onresize = function () { changeFrameHeight(); }
$(function () {
changeFrameHeight();
});
$(document).ready(function () {
//var url = getCookie('pre_url');
//if (url) {
// $("#mainiframe").attr('src', url);
//} else {
// $("#mainiframe").attr('src', '');
//}
});
function changeFrameHeight() {
var ifm = document.getElementById("mainiframe");
ifm.height = document.documentElement.clientHeight - 100;
ifm.width = document.documentElement.clientWidth - 100;
console.log("document.documentElement.clientWidth", document.documentElement.clientWidth);
console.log("document.documentElement.clientHeight", document.documentElement.clientHeight);
}
function check() {
pre_url = window.frames['mainiframe'].document.location.pathname;
if (pre_url.indexOf("blank") == -1) {
setCookie('pre_url', pre_url, 10);
}
}
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ""
}
function setCookie(c_name, value, expiredays) {
var exdate = new Date()
exdate.setDate(exdate.getDate() + expiredays)
document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";path=/;expires=" + exdate.toGMTString())
}
</script>
</body>
</html>