Select an element in HTML Widget (iframe)

Hello, I want to know the state of a checkbox but can't access to it because of the iframe.

Capture d’écran 2020-11-06 à 11.48.39

And can't access via :
var iframe = hypeDocument.getElementById('iframe').children[0];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

I read that iframe generated by widget are not "real" iframe... If someone can help me.

Will try with a rectangle...

Thanks in advance.

Found a solution with checkbox input inside a rectangle and with help of this thread (How to target Elements in a HTML Widget by @MarkHunte :+1:) :
var checkButton = hypeDocument.getElementById('elementId');

	checkButton.onclick = checkClic;
	
	function checkClic(){ 
	
		if (checkButton.checked == true){
 			console.log("true");
 		}else{
 			console.log("false");
 		}
 	}
2 Likes

I'm glad you found a solution.

Also note that in looking at that inspector screenshot, it isn't clear that you really need an HTML Widget (iframe). Could you instead use a Rectangle's Inner HTML, which is represented just as a <div>?

Yes, that's what I did, I changed from HTML widget to rectangle after the screenshoot :+1:.

1 Like