Reputation: 1314
I have an iframe which is to be promoted on other sites. I have set the minimum amount of frame size which is checked via 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";
This works, as per our test. However, I have found that users bypass it by embedding the iframe as width/height=0. The script doesn't catch it as it seems to check the actual page's size where it's embedded.
So how to check the frame's size instead?
Upvotes: 0
Views: 85
Reputation: 962
Try this function.
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 );
}
Good luck!
Upvotes: 1