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 Tetrad · Nov 05, 2009 at 10:47 PM · webplayerwebbrowserwebpage-javascript

How would I go about getting the results of a javascript variable to a string inside script?

Is it possible to get the URL that the web player object is embedded in?

From the "Unity web player and browser communication page" they have this example:

Application.ExternalEval(
 "if(document.location.host != 'unity3d.com') 
 { 
    document.location='http://unity3d.com'; 
 }" 
);

But is it possible to get what "document.location" is equal inside my scripts? Ideally it would be without modifying the page itself that the unity web player is embedded in.

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

3 Replies

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

Answer by AngryAnt · Nov 10, 2009 at 01:19 PM

To do that you would need to use both directions of browser communication. Here is one example of how it could be done:

using UnityEngine; using System.Collections;

public class WebCheck : MonoBehaviour { private string m_Address;

 public void ResolvePageAddress ()
 {
     Application.ExternalEval ("GetUnity ().SendMessage ('WebCheckGameObject', 'SetPageAddress', document.location);");
     Debug.Log (m_Address);
 }

 public void SetPageAddress (string address)
 {
     m_Address = address;
 }

}

For this script example to be working, your script would need to be in the scene on a GameObject by the name "WebCheckGameObject".

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 bernardfrancois · Jan 01, 2014 at 09:29 AM 0
Share

Simply using GetUnity() in Application.ExternalEval didn't work for me (Unity 4.3 in a Web Player build); I had to use UnityObject2.instances[0].getUnity() ins$$anonymous$$d - which worked.

avatar image
2

Answer by MyraLoveless · Nov 06, 2009 at 10:17 AM

try Application.dataPath it doesn't return the exact html file, but it does return the path. If you're going for antipiracy this should be enough. For example:

if (Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
{
    datapath = Application.dataPath;
    if(datapath == "http://mypage.com/games/mygame")
    {
        print("This is the correct page. No piracy detected.");
    }
    else
    {
        print("Dr Jones: This game doesn't belong on this webpage. It BELONGS IN A MUSEUM!\nAuctioneer:SIT DOWN Dr Jones!");
    }
}

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
1

Answer by $$anonymous$$ · Nov 07, 2009 at 09:08 PM

Check out the Unity function Application.absoluteURL. The Scripting Reference for that function also has an anti-piracy code sample using that and Application.dataPath.

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 AngryAnt ♦♦ · Nov 09, 2009 at 01:51 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/Application-absoluteURL.html

http://unity3d.com/support/documentation/ScriptReference/Application-srcValue.html

avatar image Tetrad · Nov 09, 2009 at 10:33 PM 0
Share

That returns the path of the unity3d file, not the URL of the web site it is embedded in.

$$anonymous$$y use wasn't for anti-piracy measures, it was more of an intellectual exercise to see if I could get parameters out of a URL.

avatar image AngryAnt ♦♦ · Nov 10, 2009 at 01:17 PM 0
Share

Ah! Your initial title did not immediately reflect this, which is why you got answers like these. I took the liberty of editing your title to better match your goal.

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

1 Person is following this question.

avatar image

Related Questions

Getting focus on web player 0 Answers

What is the maximum byte length of Application.ExternalCall? (and oh yea, it doesn't escape strings correctly) 3 Answers

godaddy webgame problem 1 Answer

I have a big project building for webplayer. Is there any browser to run it yet ? 3 Answers

Honeycomb web Browser support unity web player? 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