I'm writing a small script that sets the Display property for an Iframe to none if the iframe URL matches the 404 url. For instance, the iframe displays a comment box if there is a .html file that matches the name. If there is no file for that link then it redirects to the sites 404 page, which i dont want it to display.
Example: Iframe src = ~~~ItemTitle~~~.html, If no file by that name exists, redirect to 404 page, <- In which case dont display iframe.
Heres my Javascript:
// Comment Display Switch
if (document.getElementById("comment-frame").contentWindow.location.href == 'http://www.nemico.co/404') document.getElementById("comment-frame").style.display == "none";
Heres my markup:
<div align="center" id="commentbox" class="commentbox">
<iframe id="comment-frame" scrolling="no" style="overflow: auto; width: 100%; border:thick; border-color:#292F33; border-radius:5px; word-wrap: break-word;" src="~~~ItemTitle~~~.html"></iframe>
</div>
And the script is triggered via Body onload():
<BODY onload="dynamicFormat()">
Where am i going wrong here? It still displays the iframe with the 404 page. Any help would be greatly appreciated. I'm still new to stack etiquette so i apologize in advance for any errors on my part.
Here is the full dynamicFormat Script, What i included above is just the part for the comment box.
<script>
function dynamicFormat() {
var allImg = document.querySelectorAll('img')
allImg.forEach(function(img) {
const widthStr = img.style.width;
const widthNum = Number(widthStr.slice(0, widthStr.length - 2));
if (widthNum >= 35) img.style.width = '35px';
// Comment Display Switch
if (document.getElementById("comment-frame").contentWindow.location.href == 'http://www.nemico.co/404') document.getElementById("commentbox").style.display == "none";
});
}
</script>