0

javascript like:

<script type="text/javascript">
if(!alert("msg here ")) document.location = 'http://google.com';
</script>

this scirpt only go to google in a same tab or window, i want to pup up a window then go to google.com. Thanks.

yzz
  • 1
  • 1

1 Answers1

0

The unfriendly way:

<script type="text/javascript">
if(!alert("msg here")) window.open("http://google.com");
</script>

The more friendly way:

<script type="text/javascript">
if(confirm("Do you wish to go to google?")) window.open("http://google.com");
</script>
icecub
  • 8,615
  • 6
  • 41
  • 70
  • Disable popup blocker in chrome: https://productforums.google.com/forum/#!topic/chrome/m-WfaAOYRyA – icecub Sep 25 '14 at 02:37
  • thanks, but how to force my vistors to see the popup successfuly? :) – yzz Sep 25 '14 at 02:40
  • You can't. There's a reason for popup blockers to exist. You can forse browse to another address, but you can't force to popup a new window. (And even forse browse can be blocked) – icecub Sep 25 '14 at 02:41
  • what do you mean force broswer to another address? thats the goal I want to achive. yes, I want force broswer to another address. – yzz Sep 25 '14 at 02:44
  • As you did before: window.location.. meaning you use the current window to browse to another address. You can't control a users browser! It's simply wrong to open up a new window without the users consent. – icecub Sep 25 '14 at 02:47
  • oh yes. I am too evil. thanks a lot, man. its late in NL, you should get some sleep. :) – yzz Sep 25 '14 at 02:48
  • I'm working nightshifts. On topic: There's javascript function called onbeforeunload() which allows you to do stuff if the user closes the browser. What would you think if I force a popup back to my site if you close your browser? Effictively hijacking your browser making it impossible for you to leave my website. No matter what you do, it'll just popup again. Hope you understand the reason behind popup blockers now. – icecub Sep 25 '14 at 02:51
  • ah. sorry for the delay. so the function: onbeforeunload() still working for most broswers? Could you write some code for me to use it? like when you close window, popup go to another website. I know it only works for who dont have popup blockers. oh, is popunder same with popup? any popunder blockers exist? – yzz Sep 25 '14 at 04:58
  • – yzz Sep 25 '14 at 05:04
  • 1
    Sorry but this is where I draw the line. I don't mind helping with code, but if you intend to do stuff you shouldn't, you're on your own. – icecub Sep 25 '14 at 09:00
  • what do you mean? I know nothing about coding, its great if you can help me. – yzz Sep 25 '14 at 11:22