【问题标题】:Restrict iframe size限制 iframe 大小
【发布时间】:2017-07-15 06:43:19
【问题描述】:

我有一个要在其他网站上推广的 iframe。我已经设置了通过 javascript 检查的最小帧大小:

function check() {
    var w0 = screen.width;
    var h0 = screen.height;
    var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

    if ((w0 < 700) || (w < 650) || (h0 < 500) || (h < 400)) {
    window.location = "stop.html";

根据我们的测试,这是可行的。但是,我发现用户通过将 iframe 嵌入为 width/height=0 来绕过它。该脚本没有捕捉到它,因为它似乎检查了嵌入它的实际页面的大小。

那么如何检查框架的大小呢?

【问题讨论】:

    标签: javascript iframe


    【解决方案1】:

    试试这个功能。

    function alertSize() {
       var myWidth = 0, myHeight = 0;
       if( typeof( window.innerWidth ) == 'number' ) {
          //Non-IE
          myWidth = window.innerWidth;
          myHeight = window.innerHeight;
       } else if( document.documentElement && ( 
          document.documentElement.clientWidth || 
          document.documentElement.clientHeight ) ) {
          //IE 6+ in 'standards compliant mode'
          myWidth = document.documentElement.clientWidth;
          myHeight = document.documentElement.clientHeight;
       } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
          //IE 4 compatible
          myWidth = document.body.clientWidth;
          myHeight = document.body.clientHeight;
       }
       window.alert( 'Width = ' + myWidth );
       window.alert( 'Height = ' + myHeight );
    }
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2011-09-06
      • 1970-01-01
      • 2011-07-18
      • 2011-11-21
      • 2010-12-29
      • 2012-10-16
      • 2011-03-27
      • 2011-03-09
      • 2014-10-05
      相关资源
      最近更新 更多