You need to sign in to do that
Don't have an account?

How do i access iframe contentdocument in lwc ?
I want to access iframe content window in lwc. I am getting Secure Element in console. But I am not able to access it. Is there a way to access iframe content window or document once its loaded. What is the Secure Window, Secure Element, Secure Document in Locker API, how can we access those property .
Below are my code:
LwC - HTML file
<template>
<iframe src='https://domain.salesforce.com/home.jsp'/>
</template>
.js file
renderedcallback(){
const iframe = this.template.querySelector('iframe);
iframe.style.background='red';//This is working.
console.log(iframe.contentDocument or iframe.contentWindow) //I am not getting anything in console, but if i use breakpoint, it gives SecureElement in debugger. I could see all the document and DOM Element.
How do i access those element?
Thanks in Advance.
Regards,
Saravana
Below are my code:
LwC - HTML file
<template>
<iframe src='https://domain.salesforce.com/home.jsp'/>
</template>
.js file
renderedcallback(){
const iframe = this.template.querySelector('iframe);
iframe.style.background='red';//This is working.
console.log(iframe.contentDocument or iframe.contentWindow) //I am not getting anything in console, but if i use breakpoint, it gives SecureElement in debugger. I could see all the document and DOM Element.
How do i access those element?
Thanks in Advance.
Regards,
Saravana
I looked at this thread(https://github.com/salesforce/lwc/pull/1368) It seems like the suggestion to use iframe like below may work: Please check if it works for your use case too.
More reference:
https://github.com/salesforce/lwc/issues/1366
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.