允许带有警报的弹出窗口

allowing pop ups with a alert

本文关键字:窗口 许带 有警      更新时间:2023-09-26

我正在尝试这样做,当用户点击警报上的ok时,它将允许弹出我的网站。我当前的代码是:

var w = window.open( "urls","_blank", "height = 200, width = 300, top=450, left=1025" );
if(w == null || typeof(win) == "undefined" || win.location.href == 'about:blank') {
alert("You must allow pop ups before continuing, click the button to allow pop ups");
}

我如何才能做到这一点?如果不可能,我如何才能实现一种方法,让他们可以轻松地为我的网站弹出窗口,而不必通过进入浏览器设置来要求他们允许。

非常感谢

为什么不将锚标记中的href随机化?Es:

<a href="" id="randLink" target="_blank">Open a random site</a>

想象一个jquery函数:当页面第一次加载时,选择一个随机站点,并将链接放在#randLink:的href中

$(document).ready(function() {
    $('#randLink').attr('href',generateRandUrl());
});

每次单击时,都会更改href值:

$( "#randLink" ).click(function() {
 $('#randLink').attr('href',generateRandUrl());
});

generateRandUrl()是一个函数,它返回其中一个网站的字符串值