How can I make this script to pop up instead of alert

136 views Asked by At

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>

2

There are 2 answers

2
Anand On

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.

0
Antariksha On

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