Search code examples
javascripthtmliframe

Calling iframe link from other js file not working


I created an iframe in vex6.html and a js file in styles.gq/test.js and in that file there is the link and id but when I try to call the code in html it does not work.

Here is my code for vex6.html

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<script type="text/javascript" src="https://styles.gq/test.js" ></script>

<iframe id="vex6" width="100%" height="500" style="border:1px solid black;"></iframe>


</body>
</html>

here is my js code

document.getElementById("vex3").src
    = "https://www.obviousplays.tk/gfiles/vex3";

document.getElementById("vex4").src
    = "https://www.obviousplays.tk/gfiles/vex4";
    
document.getElementById("vex5").src
    = "https://www.obviousplays.tk/gfiles/vex5";
    
document.getElementById("vex6").src
    = "https://www.obviousplays.tk/Gfiles6/vex6";
    
document.getElementById("slope").src
    = "https://www.obviousplays.tk/gfiles/slope";

I expected an iframe but instead there seems to be no link for the iframe it is also spitting out the error cannot set properties of null (setting(src))


Solution

  • Add the line <script type="text/javascript" src="https://styles.gq/test.js</script> after the iframe tag.

    Worked for me.