1

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

Alfa Bondi
  • 13
  • 2

1 Answers1

1

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335