How do I open a link in a New Window (iOS)

Get help using Construct 2

Post » Wed Jun 29, 2016 12:38 pm

As per this thread: viewtopic.php?f=152&t=162902&p=1051085#p1051085

I've also noticed that iOS treats new window requests from construct exported html5 pages as pop-ups, and as it's been stated iOS safari blocks pop ups by default, and even if it wasn't I'd assume the first pop-up someone got they wouldn't have wanted and so disabled them at that point anyway.

So I want to know is it possible to fix this issue with a construct update?

Or is there a fix / workaround that we can use right now?

Thank you for any assistance!
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Thu Jun 30, 2016 8:28 pm

There is nothing Construct 2 can do to work around popup blockers - they are designed to block popup ads that would irritate the user, and anything C2 could do to circumvent it would be done by ads as well.

Generally the workaround is to only open a window in a user input trigger, such as "on object touched". Browser popup blockers allow popups in user input events, since they are treated as intentional actions by the user.
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Post » Thu Jun 30, 2016 8:46 pm

Hi thanks for the reply, I'm not sure if that work around changes anything for me though as I've only tried based on user interaction.

*UPDATE*
Ok so I created this to eliminate any other code getting in the way and to test a theory:
http://jmkit.com/linktests/
if you load up that link on an iOS device you'll see that the 'NEW' button can open up a new window just fine but the sprite 'NEW' trigger does nothing, is this a bug in the way the sprite works as a trigger?
(the SAME button and sprite open the link in the same window as expected)
Last edited by JMKit on Thu Jun 30, 2016 10:51 pm, edited 1 time in total.
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Thu Jun 30, 2016 11:04 pm

And I've noticed I can't place a button over a sprite and make it's initial visibility Invisible or even put it under a sprite so there's no hiding a working button

*Update*
So with a bit of faffing adjusting the buttons size (which can vary a lot between devices it seems) and adding CSS styles for transparent background and 0 borders, I was able to 'hide' the button over top of the sprite I wanted to open a link in a new window.

But I'd love to know if that's something that can be fixed in an update it would make C2 life that much easier for what is a small but (for my current project at least) essential element.
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Fri Jul 01, 2016 12:49 pm

JMKit wrote:if you load up that link on an iOS device you'll see that the 'NEW' button can open up a new window just fine but the sprite 'NEW' trigger does nothing, is this a bug in the way the sprite works as a trigger?

It depends on precisely which events you used, but I can't see which you used without the .capx.
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Post » Sat Jul 02, 2016 5:45 pm

well it's the simple touch way of opening a link as far as I'm aware, the capx is here:
http://jmkit.com/newwindowtest.capx
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Mon Jul 04, 2016 11:45 am

I tested this on an iPad Air 2. Both options work, but for some reason the Sprite option makes Safari prompt "This page is trying to open a new window" with options to "Allow" or "Block". I think if you block it, it never asks again, so you might think it's failing. However I found a workaround: if you use "on any touch end" followed by "is touching Sprite", it can open the popup without prompting.

I think this is related to Safari change to do with what counts as a user input event. When iOS 9 came out we had trouble with audio no longer unmuting (Safari needs a user input event to allow audio playback). They blocked "touchstart" from unmuting, but it still worked in "touchend". So we moved unmuting to "touchend" and it fixed it.

So the three approaches are:
"On button clicked" - triggers in a "click" event - Safari allows popup
"On touched Sprite" - triggers in a "touchstart" event - Safari 9+ blocks this
"On any touch end" - triggers in a "touchend" event - Safari allows this (combined with a "Is touching object" you can get the same effect as "On touched sprite" but triggering at the end of the touch instead of the start)

So you should be able to work around this already with the "On any touch end" approach.
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Post » Mon Jul 04, 2016 1:54 pm

Great!
Thanks for the work around, it's working just as the button does combining 'On any touch end' with 'is touching Sprite'

I appreciate you taking the time to help out with this issue and it's interesting to know what the issue was
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Wed Sep 13, 2017 11:14 am

@Ashley

How about keyboard?

I trying to open a new window when pressed a key and safari blocks it.

How to fix this?
B
29
S
14
G
1
Posts: 133
Reputation: 3,214


Return to How do I....?

Who is online

Users browsing this forum: jogindarpradeep, matriax and 19 guests