I have a problem with window.close() function. I have a simple HTML script:
<body>
<a href="http://www.gmail.com" class="one">gmail</a><br />
<a href="http://www.google.com" class="one">google</a><br />
<input type="submit" id="submit" name="submit" value="submit">
<script src="project.js"></script>
</body>
I want to open the above url's in different windows. Once the url's are loaded, the windows should close itself without any alerts. The below javascript code lets the url's open in different windows. But it closes only 'google.com' and the html webpage. The 'gmail' website remains open.
var submit = document.getElementById("submit");
submit.onclick = function() {
var getLinks = document.getElementsByClassName("one");
for(var i=0; i<=(getLinks.length-1); i++) {
window.open(getLinks[i]);
getLinks[i].onload = window.close();
}
}
What am I missing in this code. Any help would be appreciated. Note: the links are only for test.