javascript - how to make alert prompt only display once? -
i want alert apear once.
<head> <script type="text/javascript"> var name; name = window.prompt("enter name"); </script> </head>
this in body
<div style="left:750px;top:60px;position:absolute;"> <script type="text/javascript"> document.writeln("welcome "+name+" !"); //name request display here </script> </div>
==================================================================================
also promotion popup when page load
here promotion.html
<body> <script type="text/javascript"> popupcenter() //for name enter on request form </script> </body>
here promotion.html:-
<body> <div id="promotion"> <table border="1"> <tr><td><p> <script language="javascript"> <!-- promo = new array promo[1]="promotion!!! save 50% if buy more $300" promo[2]="open every monday saturday!!!! 9 a.m 10 p.m" promo[3]="the 100th customer win free reel & spool!!" promo[4]="labour sale day 20% off!! labour sale day 20% off!!" promo[5]="custom parts , reels bearing 10% off!!!" promo[6]="come now!! hurry!! while promotion still available!!" promo[7]="shimano $230, noww $98!!!" random_num = (math.round((math.random()*6)+1)) document.write(promo[random_num]); --> </script> </p></td></tr> </table> </div> </body>
in .js file promotion.html
function popupcenter(pageurl, title,w,h) { var left = (screen.width/2)-(w/2); var top = (screen.height/2)-(h/2); var targetwin = window.open ("promotion.html", "promotion", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width='+580+', height='+485+', top='+100+', left='+400); } return sessionstorage.popupccenter=1;
keep copy in sessionstorage, check existance ask if not there
function getname() { var n, q = 'enter name'; if (!window.sessionstorage) { // if sessionstorage not supported return window.prompt(q); // perform other action } n = window.sessionstorage.getitem('name'); if (!n) { n = window.prompt(q); window.sessionstorage.setitem('name', n); } return n; }
Comments
Post a Comment