How to execute a function optionally if the page loads inside an iframe? [duplicate]

3

Can you tell if a particular page is being opened within iframe ?

I want this page to execute a function when it loads through iframe . Otherwise, I want it not to execute.

Is there any way to do this?

    
asked by anonymous 10.05.2017 / 17:15

1 answer

0

@AndersonCarlosWoss suggestion may give security error. You have a comment here: link

One solution I found was in this post from the SO in English: link

The code is this:

var ehFrame = window.frames.length + ':' + parent.frames.length;

Basically returns:

'0:0' when there is no frame% '1:1' when executed in the "parent" window that has the iframe
'0:1' when executed in the "daughter" window

I think this should help you.

    
10.05.2017 / 17:38