我正在尝试制作支持所有浏览器(包括Safari)的网页游戏,但我遇到了在Safari中打开新标签的问题。
我的游戏在iFrame 中,在游戏结束时,会有一个"按钮"通过操作打开网页,它应该在新标签页中打开。
我的代码适用于Safari for Windows,但它在iOS上的Safari上无效。我需要它适用于:)
这是我在index.html中的iFrame代码段:
.. .. ..<section id="main-wrapper">
<div class="auto">
<div class="frame-holder">
<iframe id="air" src="my_game_url_address" width="750" height="548" frameborder="0" scrolling="no"></iframe>
</div>.. .. ..
以下是我尝试过的事情(很多事情):
//this is not working
function OpenInNewTab(url)
{
var fr = document.createElement("form");
fr.setAttribute("action",url);
fr.setAttribute("target","_blank");
fr.submit();
}
//this also not working
function openTab(url)
{
// Create link in memory
var a = window.document.createElement("a");
a.target = '_blank';
a.href = url;
// Dispatch fake click
var e = window.document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
};
//wth apple, this also not working !
function FuncnewTab()
{
console.log("CEK SAFARI 22");
var form = window.createElement("form");
form.method = "GET";
form.action = "http://www.google.com";
form.target = "_blank";
window.body.appendChild(form);
form.submit();
}
//also not working ....
function actuateLink(link)
{
console.log("CEK SAFARI 1");
var allowDefaultAction = true;
if (link.click)
{
console.log("CEK SAFARI 2");
link.click();
return;
}
else if (document.createEvent)
{
console.log("CEK SAFARI 3");
var e = document.createEvent('MouseEvents');
e.initEvent(
'click' // event type
,true // can bubble?
,true // cancelable?
);
allowDefaultAction = link.dispatchEvent(e);
}
if (allowDefaultAction)
{
console.log("CEK SAFARI 4");
var f = document.createElement('form');
f.action = link.href;
document.body.appendChild(f);
f.submit();
}
*/
console.log("CEK SAFARI 5");
link.click();
console.log("CEK SAFARI 6");
}
这些都不起作用。
任何人都可以提供帮助吗?