on my page I have a script working in an iFRAME.
That script will take parameters received from the URL to identify a user url/page?userId=fubar
Depending on the parsed userId the iFRAME script will do different things, eg:
- no userId received = response A
- registered userId received = response B
- junk userId received = response C
I think I need to be using wix-location and get queryParams() but I could do with an ELI5 guide of exactly what code I need and where to put it (in the page or the iframe) etc.
Hi Nik 
I recommend using queryParams() to get the query from the URL, then pass it to the iFrame as a message using the postMessage() function.
Page Code
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
$w.onReady(() => {
let query = wixLocation.queryParams;
let userId = query.userId;
let message = {status: null, registered: false, id: null}
if (userId !== null && userId !== undefined) {
message.status = 'exist';
if (user.loggedIn) {
message.id = user.id;
message.registered = true;
}
}
$w('#yourHtmlComponent').postMessage(message)
})
HTML Code
<script type="text/javascript">
window.onmessage = (event) => {
if (event.data) {
// Your code runs here
}
}
</script>
You can then decide what to do with ID in your html component.
Hope that helped~!
Ahmad
Thanks Ahmad, that’s super helpful!. Just for clarity is
$w('#yourHtmlComponent').postMessage(message)
the URL of my iFrame or the main page or something else?
No, you must place this line in the Page code section, you also need to change its ID from yourHtmlComponent to whatever your HTML element ID is, the HTML code will take care of the rest.
Understood on where I need to put the code, my question was what I should change " yourHtmlComponent" to. Is it the HTML of the source page or of the iFRAME?
No, the hrml/iFrame ID, the one that you’ve embedded on your site, right click on it, choose “View Properties” and copy the ID from the panel and replace the id in my code with yours.