0

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>
Phlume
  • 3,075
  • 2
  • 19
  • 38
owins
  • 1
  • 1
  • 1
    The behavior you are describing would seem to be very annoying to your users. Surely there is a better way? – radiaph Mar 13 '15 at 19:26
  • Read this question/answer: http://stackoverflow.com/questions/2587677/avoid-browser-pop-up-blockers?rq=1 – nweg Mar 13 '15 at 19:48

0 Answers0