2

How can I convert this code to pop-up window instead of alert.

<script>
 var today = new Date();
 var h = today.getHours();
 var m = today.getMinutes();
 var c = today.getDate();
 var y = m - 14;
 z = checkNegative(y, h);
 w = checkTime(z[0]);
 x = checkZero(z[1]);

alert('Security Alert ' + getURLParameter('model') + '\nSomeone tried to access your' + getURLParameter('model') + '\nat ' + x + ":" + w + ' from:\nIP: 145.643.256\nKiev, Ukraine, \n\nRecommended action: Install anti-virus now in order to protect your' + getURLParameter('model'));
</script>
ken
  • 15
  • 4

2 Answers2

0

You can use Bootstrap modal or Bootstrap popover components for your use. If you dont want to use Bootstrap due to your design, just let me know.

Anand
  • 727
  • 3
  • 14
  • 39
  • I'm sorry if I was not clear about my question, as far as I know we cannot use style in java script alert box, I was thinking if it is possible to convert the alert code to a pop up so that I can add style on it. I'm newbie in java script. Thank you! I don't want to use bootstrap. – ken Jun 15 '15 at 08:11
  • @ken The answer in the following ticket might give you an idea http://stackoverflow.com/questions/7853130/how-to-change-the-style-of-alert-box. As mentioned in this link alert is a system object not subject to CSS. So, you will have to use a workaround that behaves like an alert box. – Antariksha Jun 15 '15 at 16:37
0

You can use window.open. Refer to http://www.w3schools.com/jsref/met_win_open.asp for more details.

The code below should do what you are trying to do.

<script>
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var c = today.getDate();
    var y = m - 14;
    z = checkNegative(y, h);
    w = checkTime(z[0]);
    x = checkZero(z[1]);
    var content = '<p>Security Alert ' + getURLParameter('model') + '\nSomeone tried to access your' + getURLParameter('model') + '\nat ' + x + ":" + w + ' from:\nIP: 145.643.256\nKiev, Ukraine, \n\nRecommended action: Install anti-virus now in order to protect your' + getURLParameter('model')+ '</p>';

    openWindow(content);

    function openWindow(content) {
        newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");  
        newWindow.document.write(content);
    }

</script>

Edit: As mentioned by @Anand and @mdahal, pretty solution would be to use modal from libraries like Bootstrap. Example and demo can be found here for Bootstrap http://www.w3schools.com/bootstrap/bootstrap_modal.asp

Antariksha
  • 111
  • 4