用JavaScript (p5.js,p5.play)制作一个游戏,一旦用户收集了所有的sprite对象(存储在food数组中),它将显示一个文本(在本例中为emoji),并将打开一个指向另一个网页的窗口。这里的问题是,大多数浏览器都有弹出窗口阻止程序,理想情况下,希望用户点击附加到网页链接的表情符号,打开一个新窗口。我试过使用.onclick,但仍然不起作用...
现在的情况是,当我返回到游戏的网页时,它总是弹出一个新的窗口。对此有解决方案吗?
编辑代码的原始链接在这里;sketch.js文件上的https://glitch.com/edit/#!/kitschen-dreams第53行
if (food.length > 0) {
text(score, width / 2, height / 2);
} else {
var kitschenDreams = text("?", width / 2, height / 2);
// kitschenDreams.onclick = window.open("http://kitschendreams.tumblr.com");
// window.open("http://kitschendreams.tumblr.com");
}
}发布于 2020-05-22 16:52:29
为了防止一个窗口多次打开,可以指定一个窗口名称(Window.open()的第二个参数):
A DOMString specifying the name of the browsing context (window, <iframe> or
tab) into which to load the specified resource; if the name doesn't indicate an
existing context, a new window is created and is given the name specified by
windowName.具有相同窗口名称的连续调用重复使用先前打开的窗口。
https://stackoverflow.com/questions/61950933
复制相似问题