Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetUrl() #8

Closed
ravenfeld opened this issue Mar 4, 2013 · 4 comments
Closed

GetUrl() #8

ravenfeld opened this issue Mar 4, 2013 · 4 comments

Comments

@ravenfeld
Copy link

Is it possible to have a method getUrl which to return the current url

Thank you

@splhack
Copy link
Contributor

splhack commented Mar 4, 2013

The portable way is

// In JavaScript
window.addEventListener("onpageshow", function(){
    Unity.call("url:" + window.location.href);
}, false);
// In C#
string mUrl;

void Start()
{
    webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
    webViewObject.Init((msg)=>{
        if (msg.StartsWith("url:")) {
            mUrl = msg.Substring(4);
        }
    });
}

public string getUrl()
{
    return mUrl;
}

@splhack splhack closed this as completed Mar 4, 2013
@ravenfeld
Copy link
Author

I don't know where to put the javascript code?
windows is not an element of Unity?

thank you

@splhack
Copy link
Contributor

splhack commented Mar 6, 2013

For example,

void Start()
{
    webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
    webViewObject.Init((msg)=>{
        if (msg.StartsWith("url:")) {
            mUrl = msg.Substring(4);
        }
    });
    webViewObject.EvaluateJS(@"
        window.addEventListener('onpageshow', function(){
            Unity.call('url:' + window.location.href);
        }, false);
    ");

@oferei
Copy link

oferei commented May 21, 2013

suppose the user navigates away from the loaded page. can I query the URL of the new location somehow?

This was referenced Oct 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants