Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Safari window open on touchstart or touchend

This code is working in most android/chrome mobile browsers:

document.body.addEventListener('touchend', function (e) {
    //alert(1);
    window.open("http://test.com");
}, false)

But it is not working in iOS/Safari (tested with iPhone OS 9_2, AppleWebKit 601.1.46, Safari/601.1).

Is there any workaround to show a new window/tab with this event?

"alert(1)" is working fine, so i suppose the event is firing normally.

Thank you.

like image 729
greyman07 Avatar asked Dec 07 '25 05:12

greyman07


1 Answers

It seems that since iOS >= 9.0, you can no longer use window.open inside a "touchstart" event handler function. You can use the click instead.

I iOS 8.x you can still open a page with window.open in a "touchstart" event handler function

like image 97
PierreB Avatar answered Dec 09 '25 02:12

PierreB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!