2017-07-15 6 views
0

他のサイトで宣伝するiframeがあります。私はjavacriptを介してチェックされるフレームサイズの最小量を設定しました:iframeのサイズを制限する

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"; 

これは、私たちのテストごとに動作します。しかし、私は、ユーザーが幅/高さ= 0として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); 
} 

幸運を祈る!

関連する問題