• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 [SOLVED] Delete URL-Parameters

eimie

Member
Hello everybody,

currently I'm working on an HTML5 project (a kind of level editor) where players can share content via links. To avoid storing anything on my server, I've decided to attach URL parameters with encoded level data at the end of the link. When the user clicks Share, the editor encodes the level data and generates a link with the attached data. When someone visits the editor via this link, the editor decodes the parameters and recreates the level. This works very well, but I'm wondering if it's possible to clear the parameters from the address bar after the level has been rebuilt.

In short:

myfantastichtml5leveleditor.com/?level=9872759103721938472194 should become
myfantastichtml5leveleditor.com

I thought about something similar to the JavaScript function window.history.pushState() (here a thread on stackoverflow).

Is there a way to do this in GML without JavaScript?

Thanks :)
 

FrostyCat

Redemption Seeker
Instead of hoping to do this without JS, learn to make JS extensions and integrate it yourself.

Create an extension, then add a JS file with this in it:
Code:
function replaceHistoryState(url) {
  window.history.replaceState({}, url);
}
Then in GMS 2, add a function to that JS file named replaceHistoryState (for both the name and the external name), and set it to accept one argument. Then you can call this from within GML and set the address bar.
 

eimie

Member
It works like a charm, thanks!

I did not think it was that easy. This actually opens up a whole new world!

But I noticed that at least Firefox needs all three arguments of the function - in this case I just used an empty string:

Code:
function replaceHistoryState(url) {
    window.history.replaceState({}, "", url);
}
 
Top