Saad Awan Saad Awan - 6 months ago 21
PHP Question

get width height of iframe content

hi i want if any one use my url on iframe my code detected the ifame and also its size
like

<iframe name="test" src="http://mydomin.com/show.php" style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%" scrolling="no" border="0" frameborder="0"></iframe>


if any one use like
mydomin
on iframe my
show.php
file detect it use our url on iframe and his sizes also.
can its possible? please tell me how to do it

Answer

In your iframe you need to add the script:

if (window !== top) {
  alert(window.innerWidth + ',' + window.innerHeight);
}

This script check if your page run in iframe: (window !== top)

Then alert the width and height.

Demo:

http://output.jsbin.com/gabeze

Update

For prevent website to embed yours, the best way I know is in the server.

Just return the header X-FRAME-OPTIONS: DENY.

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a , or . Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

MDN

Comments