如何使此脚本弹出而不是警告

时间:2015-06-15 06:50:47

标签: java javascript jquery alert popupwindow

如何将此代码转换为弹出窗口而非警报。



<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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您可以使用Bootstrap modalBootstrap popover组件供您使用。如果你不想因为你的设计而使用Bootstrap,请告诉我。

答案 1 :(得分:0)

您可以使用window.open。有关详细信息,请参阅http://www.w3schools.com/jsref/met_win_open.asp

下面的代码应该做你想做的事。

<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>

编辑:正如@Anand和@mdahal所提到的,漂亮的解决方案是使用像Bootstrap这样的库中的模态。可以在此处找到Bootstrap http://www.w3schools.com/bootstrap/bootstrap_modal.asp

的示例和演示