I have an website with content, with div class card2 which has white background and some buttons (button1, button2, button3)
I have dashboard, where I load an website content using iframe (full html)
So, when user opens his dashboard, I apply the code bellow which will remove a white background from style and buttons will be on the background without white color
<script>
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
document.getElementById("biolink_preview_iframe").load = function(){}
let iframeName = document.getElementById("biolink_preview_iframe");
let iframeContent = iframeName.contentDocument;
iframeContent.body.innerHTML = iframeContent.body.innerHTML + "<style>.card2{background-color: unset !important;box-shadow: none !important}</style>";
});
</script>
When user change the order of a buttons in dashboard, it reloads and iframe, and my code above is not working anymore, white background is visible again.
Can you suggest me please, why this happening?
I tried this code
<script>
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
document.getElementById("biolink_preview_iframe").load = function(){}
let iframeName = document.getElementById("biolink_preview_iframe");
let iframeContent = iframeName.contentDocument;
iframeContent.body.innerHTML = iframeContent.body.innerHTML + "<style>.card2{background-color: unset !important;box-shadow: none !important}</style>";
});
</script>
>Solution :
Typos.
You need either
document.getElementById("biolink_preview_iframe").onload = function
OR
document.getElementById("biolink_preview_iframe").addEventListener('load', function
and you have a {} after function. You likely meant
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
document.getElementById("biolink_preview_iframe").addEventListener('load', function() {
let iframeContent = this.contentDocument;
iframeContent.body.innerHTML += "<style>.card2{background-color: unset !important;box-shadow: none !important}</style>";
});
});