Reputation: 13
So,I embedded a website on my little project and I want a specific button on that embedded website to be clicked. I tried the
function anyFunction() {
var x = document.getElementsByClassName("example");
x[1].click();
}
<embed src="embeddedwebsite" style="width:100%;height:100%;"/>
and i got nothing. Maybe it was because the button i want to click is from an embedded website. Is there any way to fixing the code. Thanks
Upvotes: 1
Views: 310
Reputation: 943213
The correct element for including another webpage is <iframe>
so start by using that:
<iframe src="embeddedwebsite"></iframe>
You can then access content in it via:
document.querySelector('iframe').contentWindow.document.getElementsByClassName("example");
… providing it is on the same origin.
Cross-origin frame access has limitations which you can work around via postMessage
.
Upvotes: 1