I am developing an extension in which i need to generate URL of website differently.Here is the structure of my code i am using
<script>
var URL="";
function genURL(){
URL="xyz";
}
</script>
<body onload="genURL()">
<iframe id="if1" src="abc"></iframe>
</body>
<script>
document.getElementById("if1").src=URL;
</script>
above code is wrong as i cannot access element if1 in script code aboveits definitions and URL is not available in below script code.If we can access URL in Script code below , my problem will be solved. Or else is there a way to generate URL directly in iframe .
Thanks
You create a function that assigns a value to
URL, but you never call the function, so the code is created but not executed. There’re a couple of ways to fix this. One is David’s way. Another is to assign a value to URL outside of the function: