I have a page that has a text box and a button. With the onclick
of the button I want a new tab to display: http://www.google.com/ncr
After 5 seconds, this tab should close and bring the user back to main page.
After 5 sec it should open the specified url (written on first script) in a new tab. Howerver, with the delay script running, it doesn't open new tab... rather it shows me a "pop up blocked" message. It asks to allow popup and when I allow, it opens the requested url. I do not want to allow the pop up manually.
CODE
<form>
<input type="text" id="mySearch" name="search">
<button id="shopid" onclick="openLink()" class="shop">Search</button>
</form>
<script>
var link;
function openLink(){
var x = document.getElementById("mySearch");
var currentVal = x.value;
var shop_url = "https://www.google.com/search?output=search&tbm=shop&q=" + currentVal;
link = window.open(shop_url);
}
setTimeout('openLink', 9000);
</script>
<script type="text/javascript">
(function() {
document.getElementById("shopid").onclick = function() {
var wnd = window.open("http://www.google.com/ncr");
setTimeout(function() {
wnd.close();
}, 5000);
return false;
};
})();
</script>