HTML5 HTML5 - URI query components

Mert

Member
Hi.

I am trying to redirect the player depending on the URI query component that they arrive. This can be in other situations as well. By default, my game's URL is as the follows:

Code:
https://mygameurl.com/index.html
Now, I wish to achieve something like this.
Code:
https://mygameurl.com/play/mage
/play : Indicates the menu, /mage : Indicates the class that the player wants.

I'll probably need to use URLSearchParams Javascript functions. I can very well write Javascript extensions; no worries.
What would I need? Thanks
 

gnysek

Member
You need to redirect all queries to index.html using .htaccess (apache) or nginx config, then you can try to use JS History API using push and pop callbacks ( https://developer.mozilla.org/en-US/docs/Web/API/History_API ). This might however cause page reloads so game is reloaded too, so using "hashbang" (adding param after # or after #!) might be safer. If it's needed only on game state, then window.location regex match may be enough.
 

Mert

Member
You need to redirect all queries to index.html using .htaccess (apache) or nginx config, then you can try to use JS History API using push and pop callbacks ( https://developer.mozilla.org/en-US/docs/Web/API/History_API ). This might however cause page reloads so game is reloaded too, so using "hashbang" (adding param after # or after #!) might be safer. If it's needed only on game state, then window.location regex match may be enough.
Thank you very much. Taking a look into htaccess now
 

jzavala

New Member
YYG Staff
Hi Mert

I was working in something similar yesterday, not exactly in the .index of the html export, but I hope this code help you to make a new extension

using a url like this:

You can get the data in this way:

JavaScript:
let urlParams = new URLSearchParams(window.location.search);
let uid = urlParams.get('uid');
let name = urlParams.get('name');

Regards
 
Last edited:

rwkay

YoYo Games Staff
YYG Staff
the GML functions parameter_count() and parameter_string() should give you the URL params already (not the name of the URL afaik though) - try it out

Russell
 

chamaeleon

Member
Perhaps a .htaccess rewrite rule like this would work in combination with the GML functions for getting parameters (assuming the game is at the root)
Code:
RewriteRule "^/play/(.+)" "/?class=$1" [R,L]
 
Top