00:00
00:00
Newgrounds Background Image Theme

SevsArtCave just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Getting the url params of outside iframe

198 Views | 2 Replies
New Topic Respond to this Topic

Ahoy,


I'd like to get the params of the newgrounds website from a game that's in an iframe on Newgrounds.


I'm creating an invite system that allows the player to share a url with their friends to play them.


We can do stuff like

let searchParams = new URLSearchParams(window.location.search)
param = searchParams.get('invite')

However, to get the url of the parent we can do

var url = document.referrer

or

var url = (parent !== window) ? document.referrer : document.location;

is there a way I can do this but obtain the actual params?

I'm thinking the answers no, because newgrounds hosts the games on a subdomain and there's the crossorigin request stuff that'll get in the way.


But heyho, just trying my luck, is it possible?


Cheers


UPDATE: maybe there's a way via the API?


I suspect you're right and it's not possible, I get cross origin request blocks if I try to do anything along those lines.


I'm guessing the game's being run from a server since multiple players would playing directly with each other -- maybe take another approach (if you can do this from the server) of having player A invite player B (will need to know their NG user name), player B gets a link to the game's regular page without a query string, the server checks the user name (via the API) of anyone who joins, and if player A's invite to player B is still active and player B logs in it gives them an option of joining player A's game? The drawback is that players would have to have NG accounts (at least the invite-ee).


My newsfeed has random GameDev tips & tricks

Response to Getting the url params of outside iframe 2021-07-03 19:09:36


Wow! Great idea! Thank you so much!! I definitely wouldn't have thought of that!


At 7/2/21 10:40 AM, 3p0ch wrote:I suspect you're right and it's not possible, I get cross origin request blocks if I try to do anything along those lines.

I'm guessing the game's being run from a server since multiple players would playing directly with each other -- maybe take another approach (if you can do this from the server) of having player A invite player B (will need to know their NG user name), player B gets a link to the game's regular page without a query string, the server checks the user name (via the API) of anyone who joins, and if player A's invite to player B is still active and player B logs in it gives them an option of joining player A's game? The drawback is that players would have to have NG accounts (at least the invite-ee).