How do I read the current url?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello!

    Is there a way to read the current url the project/game is running on?

    Because when I can read the url I can try to extract the access/login token from the url.

    I tried this property to read the url:

    window.location.href;

    But no success so far. window.location.href should return the current url, right? When I insert this to the browser debug console it displays the correct url. But when I set a global variable to this via script the variable remains blank.

    Thank you in advance! :)

  • If it works in the browser console, it should work in scripting too. It must be a mistake in your code.

  • Oh nevermind. You are right. I had this piece of script at a wrong place.

    Thank you for your quick help. Very appreciated. :)

    Do you know how I could use this to read the access token of an url? I'm currently trying to do it with substring, slice and so on but I'm a novice in javascript. Maybe there is an easier way. :D

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hello past me. I have come across a working solution:

    On start of layout call the function that we define in the scripts.

    If there is no Token in the url the global variable access_token will only contain "Bearer ". In that case it will forward to the login-page.

    Here is how the Token is read from the url.

    window.location.href will return the full url. We slice out the part where the Token starts ("ey") until the part where it ends ("&token_type").

    Now we got the Access Token and can use it within the value part of the AJAX: Set request header.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)