How do I open new url without get blocked by the browser

0 favourites
  • 11 posts
From the Asset Store
In this template the music plays without looping in your game
  • Using the HTML5 version if i open an url in the same page no problems.

    But with "Open URL in new window" the browser(Firefox) catch it and deny the action(With some yellow alert saying that "this page tried to open a new window and firefox blocked it" , ( on Chrome/Opera works.).

    I tried to upload my game in some site, and the other games in the site opens a url in a new window without problem, but from mine it's blocked.

    So, is there anyway in C2 to add some event or something to do it correctly or some way to fix that?

  • You can't. Those are anti-spam devices integrated into browsers to prevent annoying advertisement developers from doing exactly what you are trying to do.

  • And why from flash and other games in the same site the external links in a new windows are allowed without problems but the same thing from my game are blocked?

  • Last time I checked (a whiiiile ago) if the condition was directly an ->on clicked event it worked, if wrapped in a function, it blocked it.

    So my guess is that the open url in a new window has to be a user input response. Could be wrong though.

  • Mines are: On clickd on a object > Browser Go to X url in a new window with "New Window" tag.

  • just tried it, it does not do it with the button object >on clicked condition, maybe by having an invisible button over your object you can trick it, will do some tests if I have time...

    edit: nevermind, invisible buttons don't work, will see if I can set the opacity to 0

    Edit2: having a Visible button with the css style set like this:

    will make it invisible while functionnal it seems with this condition

    all you have to do is to have the button over the actual thing you want the user to click and firefox seems to not mind, only tested in preview though

    Edit3: https://1drv.ms/u/s!AjkoCSebIn9Jix06aurQIbxLVv-J just did a capx to show it, it places the button over the sprite and sets its opacity to 0 when created, then it basically uses the >on clicked of the button object and firefox seems to not mind at all, result testable here: http://testing-stuff-out-open-url-firef ... alloon.com

  • Yes, your trick works, thanks, So to all links to social profiles and other things like upload score i have to add a invisible button? arggg

    Mmmm so seems depending which object is clicked, construct2 open the new tab in different way? or i'm missing something?

    And there is no way to do the same only with click on a object(sprite) ? Why that difference?

    At least now i know C2 can do it, i will keep trying to see if i can achieve the same thing without add invisible buttons in all the layouts.

    Maybe Ashley can fix that on sprites for next release?

  • I think this has to do with the fact form controls are not inside the canvas, but rather part of the actual webpage (which is why they are always on top and lags when moving), so firefox may say "that is ok, that's a guaranted user gesture on the website right there". Could be wrong though, but I sincerely hope there is a better solution for this.

    also in the end I did not used the mouse object at all.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • And why from flash and other games in the same site the external links in a new windows are allowed without problems but the same thing from my game are blocked?

    Because they use ActionScript, which is inherently insecure and annoying. :-p

  • Aphrodite you are the best man! Your trick worked perfectly! Thanks, man!

  • (Not working anymore, was worth a shot though, nice trick for as long as it lasted.)

    My bad, it works. I had a wait inside the button click for an animation and removing that allowed it to work since the user invoked the navigate and it happened in the same function.

    function g(){
      setTimeout(o, 1);
    }
    function o(){
      window.open('page.php');
    }
    $('button').addEvent('click', g);[/code:7t6s1819]
    
    This will trigger the popul blocked due to the timeout.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)