Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read webkitAllowFullScreen attribute in iframe using javascript

For the following iframe code:

<iframe src="testA.html" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Inside testA.html, how do I tell if the webkitAllowFullScreen attribute is included using javascript?

like image 215
wwwuser Avatar asked Dec 12 '11 23:12

wwwuser


People also ask

What is iframe sandbox attribute?

The sandbox attribute enables an extra set of restrictions for the content in the iframe. When the sandbox attribute is present, and it will: treat the content as being from a unique origin. block form submission. block script execution.

How do I fix refused connection in iframe?

You cannot fix this from Power Apps Portal side. Most probably web site that you try to embed as an iframe doesn't allow to be embedded. You need to update X-Frame-Options on the website that you are trying to embed to allow your Power Apps Portal (if you have control over that website).

What is Srcdoc attribute in HTML?

The srcdoc attribute specifies the HTML content of the page to show in the inline frame. Tip: This attribute is expected to be used together with the sandbox and seamless attributes. If a browser supports the srcdoc attribute, it will override the content specified in the src attribute (if present).


2 Answers

If the allowfullscreen attributes are added to the iframe the variable below should be true

var fullscreenEnabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled;

This even works when the iframe src is on a different domain.
Note: the letter s in fullscreenEnabled is uppercase for Firefox

like image 136
luwes Avatar answered Oct 17 '22 20:10

luwes


This is the most robust solution:

if(window.frameElement && window.frameElement.hasAttribute("webkitAllowFullScreen")){

}

It utilizes window.frameElement, which returns the DOM node of the parent framing element, which you can then make a hasAttribute call against.

like image 32
Yahel Avatar answered Oct 17 '22 18:10

Yahel