I have an iframe and i would like to make an if condition that if the iframe source is equal to a speciefied page a div should show:
Example
if(getElementById('iframe').src = 'someurl'){
getElementById('div').style.display. = 'block';
}
The Problem
I am not an expert in JS but when I use this script the iframe loads “someurl” automatically asoon as the main page is loaded, which I don’t want, I want the div to be displayed when the iframe source changes to “someurl” via a link. The link is working fine and it changes the iframe src but the if statement isn’t working.
=is an assignment==is an equality test===is an equality test without type casting (and is generally prefered to==Use
===, not=.Then you need to reference
getElementByIdcorrectly. It is a method of thedocumentobject, not a global.Use
document.getElementByIdnotgetElementByIdThen, you’ll need to get rid of the trailing
.character from your display property.Then, assuming you want to update this when a link in the frame is followed and not just when a link in the current page is followed, you need to rerun the function periodically to see if it has changed.
Then, since the page might move away from the URL you are looking for, you need to add an else statement