0

我正在尝试获取我的页面 url 以添加页面高度的参数,以便我可以将其设置为在 iframe 中加载的页面上的动态高度。

iframe 页面代码。

$(document).ready(function() {
var h = $("#tr").height();
var pathname = $(location).attr('href');
pathname = $(this) + "&height=" + h;
});

在 iframe 中加载的页面。

$(document).ready(function() {
// parse params in iframe url

var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
    var p=a[i].split('=');
    if (p.length != 2) continue;
    b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
    return b;
})(window.location.search.substr(1).split('&'));

// get height param
var myheight = qs["height"]
// apply css height of the iframe parent
$("#frame").css("height", myheight)
});

问题是到目前为止 iframe 页面没有在页面加载时添加“page.html&height=800”,我试图弄清楚如何将它设置为在不刷新的情况下做到这一点。

4

1 回答 1

3

使用 URL 哈希,而不是参数。

 "page.html#height=800"

document.location.hash持有“height=800”,您可以对其进行解析(或设置)。

您可以更改哈希值而不影响页面加载。

于 2012-10-25T15:39:38.550 回答