html - Open popup in a new window by clicking a button in Javascript Alert -
i'm using code:
<script type="text/javascript"> window.alert("click ok if on 18"); window.open( '.html', '_blank' // <- makes open in new window. ); </script>
i need add code open popup in new window:
<script type='text/javascript' src='address popup'></script>
if add in way:
<script type="text/javascript"> window.alert("click ok if on 18"); window.open( 'address popup', '_blank' // <- makes open in new window. ); </script>
it doesn't open expected. see text. maybe it's because did not use src:
. can do?
the first parameter of window.open()
needs url of page want open in popup.
rather using alert, sounds should use confirm. alert doesn't allow user aren't 18; if close alert instead of hitting "ok", it'll still continue open pop-up. confirm() gives them "ok" button , "cancel" button, can choose.
so altogether, here's code might like:
<script type="text/javascript"> var iseighteen = window.confirm("click ok if on 18"); if (iseighteen) { // if clicked "ok" window.open( 'http://example.com/popup-is18.html', '_blank' ); } else { // if clicked "cancel" window.open( 'http://example.com/popup-not18.html', '_blank' ); } </script>
it looks trying include javascript file. if did that, you'd want put inside of script tag above file, some_name_you_can_make_up.js
, , this:
<script type="text/javascript" src="http://example.com/some_name_you_can_make_up.js"></script>
Comments
Post a Comment