Haxe / OpenFL代码:
import openfl.net.URLRequest;
import openfl.Lib;
Lib.getURL (new URLRequest (url), "_self");
// Opens the linked document in the same window or tab as it was clicked
Lib.getURL (new URLRequest (url), "_blank");
// Opens the linked document in a new window or tab. (this is default)
但是,第二个选项会生成被Chrome阻止的弹出窗口。
如何在不被阻止的情况下打开另一个标签中的链接?
使用Javascript工作:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>OpenNewTab</title>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
</head>
<body>
<center>
<canvas id="myCanvas" width="200" height="200" style="border-style: solid; border-width: 1px"> </canvas>
</center>
<script>
var canvas;
var linkURL = "http://www.google.com";
createLink();
function createLink() {
canvas = document.getElementById("myCanvas");
canvas.addEventListener("click", Link_click, false);
}
function Link_click(e) {
window.open(linkURL,'_blank');
}
</script>
</body>
</html>
P.s:我使用Stencyl和HTML / JavaScript。
答案 0 :(得分:0)
我相信如果从用户触发的事件(如指针向下,单击)打开弹出窗口,则弹出窗口阻止程序不应阻止打开它。
注意:我个人觉得开发人员决定如何打开一个窗口,为什么不让用户自己决定呢?
答案 1 :(得分:0)
虽然我找不到更好的解决方案,但我会用它:
html_message = UserMailer.welcome_email(@user).message
some_api.send_email(from, to, subject, html_message)