So I’m trying to use javascript to pop up a video, and need to know when I’m in an iframe so I can resize the video accordingly.
When outside the iframe, I see three alerts (‘this is seen by both’, ‘not in iframe’, and ‘this is after the fact’)
When in the iframe, I just see the first alert (‘this is seen by both’).
var handleViewVideoClick = function (dataAction, eventType, targetElement, dataActionElement) {
alert('this is seen by both');
if ($('iframe', window.parent.document).length == 0) {
alert('not in iframe');
} else {
alert('in iframe');
}
alert('this is after the fact...');
};
What’s going on here?
My guess would be you’re not loading jQuery in that window, resulting in a
$ is undefinederror. But no worries, you don’t need jQuery anyway, just check if the current frame is also the top frame, like this: