Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Lockstep · Jan 22, 2014 at 10:34 AM · eventlink

Open a link without popup-blocker

Hi. I want to create a button which opens a link to a new webpage. Currently I use the following inside of a OnMouseDown method:

 Application.ExternalEval("window.open('" + url + "','_blank')");

However this gets rightfully blocked by any popup blocker. I've done some research and found out, that the blocker only allows this when the funktion was called by a user event like the onclick event.

Outside of unity you could use the events like this (in a form class):

 private Button someButton;
 private EventHandler buttonEvent;
 
 //inside of the constructor:
 buttonEvent = new EventHandler(buttonFunktion);
 someButton = new Button();
 someButton.Click += newFormEvent;
 
 private void buttonFunktion(object o, eventArgs e){}


My problem is that I have no idea how I could access the events which get fired when I press a mouse button over a collider.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image roojerry · Feb 06, 2014 at 02:47 PM 0
Share

Even if you were to somehow fake an onclick user event to open a link (which I tried but was still unable to avoid the popup blocker), you will not be able to run custom javascript from a site like kongregate. There isn't anything from the unity side that will allow you to bypass pop-up blockers (and probably with good reason), other than just redirecting from the current page with Application.OpenURL. It may be time to rethink how you will handle your credits/sponsors. hard coded credits? links in description?

Also, what is the major concern with these links being caught by a blocker? The sites will still be accessible and it doesn't sound like missing the blocked links would be detrimental to the gameplay (i.e. needing a code from an external page to continue gameplay).

avatar image Lockstep · Feb 06, 2014 at 07:32 PM 0
Share

I don't really want to bypass the popup-blocker. I simply want to make my credits links to work immediately. One reason is that I want to save the players the trouble of turning of the blocker. The other is the courtacy towards those I want to give credit to. They might loose some clicks because not everybody will turn of their blocker to check out some site.

Since it works with flash, I was wondering if this is possible with unity too.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Jan 29, 2014 at 01:13 AM

If your WebPlayer knows which page it's going to be shown on, you can call JavaScript that's on that page.

The Unity manual offers a pretty simple example, which I'll quote below.

Example page contains the following JS:

 <script type="text/javascript" language="javascript">
 <!--
 function SayHello( arg )
 {
     // show the message
     alert( arg );
 }
 -->
 </script>

Example WebPlayer app calls the following:

 Application.ExternalCall( "SayHello", "The game says hello!" );
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lockstep · Jan 29, 2014 at 01:36 AM 0
Share

Thanks for your reply.

Unfortunately the page does not know anything about what I'm going to link to.

I'm asking for the case of a game on a commercial games site like kongragate. The links I want to provide are credits links and (hopefully) sponsor links. So there is no way I can modify the page to set up custom js functions.

Besides: Since this would be pure js I'm pretty sure, that this would be cought by a popup-blocker too.

avatar image rutter · Jan 29, 2014 at 01:47 AM 0
Share

I haven't tried it, and it seems a little shady, but you might be able to use Application.ExternalEval to inject extra script tags into the page.

avatar image Lockstep · Jan 29, 2014 at 05:20 PM 0
Share

Let's overlook the fact that I'd feel pretty uncomfortable messing with other peoples web-sites.

This would still not work! I built a small test project which calls a function with window.open ... on its site into my dropbox. Result was, that the popup-blocker caught this.

The blocker will catch everything that was not fired by a user events. Not matter if it is from the webplayer or the site itself.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Open a link 1 Answer

Input versus Event 1 Answer

How to fix this for c#? 1 Answer

How do I access a static event in another function? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges