Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
10
Question by Vagonn · Jan 26, 2016 at 06:23 PM · webglbrowserurltab

WebGL - Open URL in new tab?

How to open URL in new tab for WebGL?

Tried Application.OpenURL(). But it's opens a tab in same window

Thanks

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

10 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Vagonn · Jan 27, 2016 at 06:56 AM

http://va.lent.in/opening-links-in-a-unity-webgl-project/

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 OUTERDARKNESS · Jan 16, 2019 at 06:47 PM 3
Share

This is now a dead link. Can you summarize the solution?

avatar image Vagonn OUTERDARKNESS · Sep 01, 2021 at 05:57 AM 0
Share

Sorry for late answer, but links works

avatar image JuanMaldonado · Sep 09, 2021 at 02:23 AM 0
Share

Use onpointerup for touch input compatibility

 mergeInto(LibraryManager.library, { 
 OpenWindow: function(link) {
         var url = Pointer_stringify(link);
         document.onpointerup = function() { //Use onpointerup for touch input compatibility
             window.open(url);
             document.onpointerup = null;
         }
     },
  });
 
avatar image
10

Answer by dppc · Jan 27, 2016 at 05:48 AM

Like this:

 Application.ExternalEval("window.open(\"http://www.unity3d.com\")");

See http://docs.unity3d.com/ScriptReference/Application.ExternalEval.html for more info.

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 alexandr-melekhin · Jun 21, 2017 at 02:10 PM 3
Share

Be aware. Open link in new tab is blocked by chrome.

avatar image d2clon · Feb 26, 2021 at 08:42 AM 0
Share

Application.ExternalEval is deprecated check my answer: http://answers.unity.com/answers/1817839/view.html

avatar image
7

Answer by Teadaddy · Jan 26, 2016 at 11:06 PM

this has been needed for some time apparently, I am looking for some sort of workaround as well - please vote for this topic to be addressed by Unity, now that webGL is working, this needs to be implemented.

http://answers.unity3d.com/questions/32531/applicationopenurl-on-webplayer-to-open-in-a-new-t.html

Here is the correct answer to this question, posted beneath by Vagonn

http://va.lent.in/opening-links-in-a-unity-webgl-project/

Thanks! works like a charm

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
2

Answer by d2clon · Feb 26, 2021 at 08:42 AM

Application.ExternalEval is deprecated, the new way is using a .jslib file with description of the js functions you want to use in your C# code:

  • https://docs.unity3d.com/530/Documentation/Manual/webgl-interactingwithbrowserscripting.html

For our case we need:

 // Assets/Pluging/JSUtils.jslib
 mergeInto(LibraryManager.library, {
   OpenURLInExternalWindow: function (url) {
     window.open(Pointer_stringify(url), "_blank");
   }
 });

And:

 # Scripts/MyControler.cs
 using UnityEngine;
 using System.Runtime.InteropServices;
 
 public class MyController : MonoBehaviour
 {
     [DllImport("__Internal")]
     private static extern void OpenURLInExternalWindow(string url);
 
     public void OpenMyUrl()
     {
         OpenURLInExternalWindow("https://myurl.com");
     }
 }

 




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 GilesDMiddleton · Apr 22, 2017 at 05:56 PM

dppc was nearly right. The actual answer to open in a new window is to call with a 2nd parameter, replacing _blank with the name of the window you want to repeatedly target (or keep it as _blank for a new window each time).

 Application.ExternalEval("window.open(\"http://www.unity3d.com\",\"_blank\")");

However, you'll need to call something different if you want to open a URL when not in WebGL. Also, if you're trying to open social links things get more complicated, as you might want to call the native version.

     public void OpenTwitter()
     {
         if( Application.platform==RuntimePlatform.WebGLPlayer )
         {
             Application.ExternalEval("window.open(\"https://www.twitter.com/GilesDMiddleton\",\"_blank\")");
             return;
         }
         float startTime = Time.timeSinceLevelLoad;
 
         //open the twitter  app
         Application.OpenURL( "twitter:///user?screen_name=GilesDMiddleton" );
 
         if (Time.timeSinceLevelLoad - startTime <= 1f)
         {
             // typically a user takes a second to open twitter and decide what to do
             // so if the function took less than a second, it's likely it failed
             // try using normal URL opening
             Application.OpenURL( "https://www.twitter.com/GilesDMiddleton" );
         }
     }
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
  • 1
  • 2
  • ›

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

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

Related Questions

load URL images in Webgl. 1 Answer

Game pauses when user changes browser tab (even with RunInBackground) 1 Answer

Unity WebGL switch to already opened tab 1 Answer

Issue with shaders and WebGL 1 Answer

Can't run my project on browser after uploading on the server. 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