I am trying to write JavaScript code that will execute once the child page (created with window.open
function) is loaded completely.
I tried functions like window.onload
and window.setTimeout
but none seem to work. I tried to use different browsers too, but no luck.
I have a HTML file, myhtml.html, which calls an external JavaScript file, Test1.js. Test1.js opens a webpage (www.google.com) then generates a popup.
HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testin page</title>
<script type="text/javascript" src="Test1.js"></script>
<script type="text/javascript">
function callValidation()
{
var p;
var i=1;
if(document.getElementById("radio1").checked){
p="radio1";
}
directValidation(p);
alert("Ending script");
}
</script>
</head>
<body>
<h1><em><strong>Test Page</strong></em></h1>
<h4><em><strong>Version 1.0</strong></em></h4>
<form name="mainf" id = "mainf">
<input id="radio1" name ="radio1" type="radio" value = "Test Button"/>
<input type = "submit" name="submit" OnClick="callValidation();"/>
</form>
</body>
</html>
Test1.js:
var p;
function directValidation(p)
{
alert(p);
if (p="radio1")
{
fun1();
}
}
function fun1()
{
window.open("http://www.google.com");
window.onload = function(){ alert('Not Working!!'); }
alert("It is working but without waiting for page to load!! The above alert box didn't work");
}
In the above code, alert('Not Working!!');
, is not executing.
alert("It is working but without waiting for page to load!! The above alert box didn't work");
is executing before loading www.google.com.
In the above code I even tried the method: window.setTimeout('',5000);
but I'm not able to get a 5-second delay with this either.