使用jQuery在页面上重新加载iFrame

时间:2017-09-07 09:00:20

标签: javascript jquery iframe

我使用来自控制器的文件流iframe(pdf文件):

 <iframe id="#f1" src="@Url.Action("fileStream", "Approve", new { EAN = Model.ID_EAN })" style="min-height:500px; max-height:100%; min-width:100%;" frameborder="0"></iframe>

我需要在页面调整大小时重新加载此iframe。

所以我创建了jQuery函数:

jQuery(function($) {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    $(window).resize(function() {
        if (windowWidth != $(window).width() || windowHeight != $(window).height()) {
            $('#f1').attr('src', $('#f1').attr('src'));
            return;
        }
    });
});

但它不起作用。你能请求我解决方案吗?

1 个答案:

答案 0 :(得分:0)

<强>解决方案

jQuery(function ($) {
            var windowWidth = $(window).width();
            var windowHeight = $(window).height();

            $(window).resize(function () {
                if (windowWidth != $(window).width() || windowHeight != $(window).height()) {
                    window.frames['here'].location.reload();
                    return;
                }
            });
        });

iframe的名称=&#34;此处&#34;