I am trying to make a web game that support all browser (including Safari), but I am having a problem with opening a new tab in safari.
My game is inside an iFrame, and at the end of my game, there will be a "button" with action to open a webpage onit and it should be opened in new tab.
My code is works on Safari for Windows but it doesnt work on Safari in iOS. I need it to works on both :)
Here's my snippet for iFrame in index.html:
.. .. ..<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>.. .. ..
Below are something (many things) I've tried to do it :
//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");
}
None of those are working.
Anyone can help?