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
2
Question by stark89 · Jun 05, 2013 at 09:57 AM · webplayerhttp

Unity web player opening link in new tab

Hi,

Am currently working on a client project in which I am required to open a link in new tab. I tried using

Application.OpenUrl("www.mylink.com");

where in the page opens up in the current tab. I also tried

Application.ExternalEval("window.open('www.mylink.com')'")

where the page opens in a new pop-up window and is caught by the browsers popup blocker.

Is there any other work around to open links via unity web player?

Thanks in advance.

Comment
Add comment · Show 1
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 enepomnyaschih · Nov 17, 2014 at 11:58 AM 0
Share

To be short: are there any plans to add a built-in option in Unity API to open a link in a new browser tab?

Let me explain. I couldn't make JavaScript solution to work. Either I misunderstood it, or Unity Web player has been changed since the date of ytc's response, but JavaScript doesn't receive any mouse events for Unity player container in Firefox and Chrome for me.

I tried to listen the events in a transparent div element covering the whole player, but it doesn't receive any events either. I tried to produce a workaround placing my link in an opaque jQuery UI dialog, and it works perfectly in Firefox, but in Google Chrome it is completely overlapped by Unity player.

I understand that changing Unity API to support this feature is difficult to make because of security issues, but it would be great.

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · Jun 05, 2013 at 02:02 PM

Get the webplayer to talk to the hosting webpage, and then have Javascript in the html page do what you want.

See: http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html

Comment
Add comment · Show 1 · 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 stark89 · Jun 06, 2013 at 05:49 AM 0
Share

that probably is the best way to go abt it. :) but I am not too familiar with javascript. When I deliver the build I just need to upload the .unity3d file and the client does the rest.

Any idea how to implement this?

avatar image
-1

Answer by Stormizin · Jun 05, 2013 at 02:25 PM

 Application.OpenUrl("http://www.google.com");

This code in production mode(compiled for webplayer) already open that link ina a new tab.

Comment
Add comment · Show 9 · 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 stark89 · Jun 06, 2013 at 05:44 AM 0
Share

yeah i tried that, but it opens the link in the current tab. So my current game is lost :(

avatar image Stormizin · Jun 06, 2013 at 06:17 PM 0
Share

Dude, there is no built-in support for this, so yes, you need to implement this using Application.ExternalCall

avatar image Stormizin · Jun 06, 2013 at 06:18 PM 0
Share

You can use something like:

 Application.ExternalEval("window.open('http://your http://site.com','Window title')");
avatar image stark89 · Jun 06, 2013 at 06:59 PM 0
Share

check my original post! I tried tat, but it opens up the page as a pop-up and most browsers have pop-up blockers enabled :(

avatar image ByteSheep · Jun 06, 2013 at 08:02 PM 2
Share

http://stackoverflow.com/questions/12247368/javascript-window-open-function-opens-link-without-popup-blocker

Popup blockers will block any attempt to open a new tab/window through pure javascript.
The only way to get around it is by calling window.open() on a user event, such as the onclick event..

 Application.ExternalEval("var link=document.getElementById('newtablink'); link.onclick=function() { window.open('http://site.com','_blank') }");

This means you would need the user to click a link on the page, to avoid the pop up blocker denying your request.

Show more comments
avatar image
0

Answer by BenoitFreslon · Jun 25, 2014 at 10:41 AM

Still impossible to open a new tab in Unity 4.5 ?

Thanks.

Comment
Add comment · 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
0

Answer by ytc · Jul 10, 2014 at 12:11 AM

finally figure out a way to do it, not sure it will be working in all cases. have to use Application.ExternalCall in unity and javascript in the page hosting the unity webplayer.

in untiy on the object, add a script (in C#) to trigger on/off signal using a int:

 void OnHover (bool isOver) {
 //originally using onClick, but it didnt work well with mouseup with the webpage javascript, any one can try using onMouseUp etc other than Hover
             if (isOver) {
                             Application.ExternalCall ("OpenInNewTab", 1);
             }else {
                 
                 Application.ExternalCall ("OpenInNewTab", 0);            
             }    
         }

the javascript as follow:

     function OpenInNewTab(val) {
     var link=document.getElementById('divID');//the div id enclosing the webplayer 
     link.onmouseup=function() { //originally trigger the signal by onClick in unity, but later i shift to trigger through hover of the div
     if(val==1){ window.open('siteurl');
     val=0;
      }else{
     // console.log("no");
      }
     }}



hope this helps.

Comment
Add comment · Show 2 · 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 ByteSheep · Jul 10, 2014 at 12:39 AM 0
Share

I don't see how this differs to the previous suggestions seeing as you still need to click an item on the html page to prevent the new page being blocked by pop-up blockers..
Although you could try checking for the onmouseover event of the entire html element in combination with your "val" variable approach. So the onmouseover event would be called constantly but you would only call window.open() if val was 1.

Let me know if I misunderstood your solution :D

avatar image ytc · Jul 10, 2014 at 02:09 AM 0
Share

um...well, you can see it as an elaboration/ example from the above suggestions. Yes, still need the click event, trigger other than click, like mousemove etc. still causing a pop up window. I think this part is about the javascript behaviour, you can dig more or google for solution. http://stackoverflow.com/questions/15818892/chrome-javascript-window-open-in-new-tab

I have tried all the above suggestions, found even with a click event, any call of action on window opening from the unity webplayer will either create a pop-up window or open in the current, so I let the html handle the click event and the url opening. Since my case is to open a link through a button click in the unity, the val 1 / 0 triggering from the unity is aimed for the object specific when the click event happen.(@merry_christmas, you got it right)

avatar image
0

Answer by teophilik · Sep 27, 2016 at 12:09 PM

Try this method and you wont have any popup block problems. It worked for me https://www.youtube.com/watch?v=_D5deiE_r9c

Comment
Add comment · 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

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

23 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 avatar image avatar image

Related Questions

WWW class and HTTP Headers 3 Answers

Get information from response 0 Answers

How to load a prefab / object from a http source (e.g. REST API)? 2 Answers

IOS HTTP GET with Authorization Header not being sent 0 Answers

Firebase Cloud Functions with Unity using HTTP-callable function. Help needed. 0 Answers


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