How to reload parent page in JS

Question:
When using ReplAuth inside an iframe, it reloads the page within the iframe instead of reloading the parent page. Thus, it does this:

Instead of this:

The top navbar is the parent page. I have used ReplAuth and it then reloaded the URL within the iframe without affecting the parent page, thus nesting the page within itself. Once logged in, refreshing the parent page will fix this, but it’s a manual fix.

Repl link:
https://replit.com/@CoderElijah/PikaBot-Archives#static/js/auth.js
https://replit.com/@CoderElijah/PikaBot-Archives#templates/auth.html
https://replit.com/@CoderElijah/PikaBot-Archives#main.py
These are the three relevant files within the Repl. Lines 149-170 in main.py are where the ReplAuth HTML page is used.

In summary, I want to reload the parent page, not just the iframe. Similar to using target='_parent' in HTML hyperlinks.

in auth.js, change location.reload(); (L42) to window.opener.location.reload();.

Related SO question: javascript - Reload parent window from child window - Stack Overflow

That didn’t work. I’ll look at that website for more ways to try this.

That is because of this: authed="location.replace('/upload')" on the script tag. Try removing that.

Removing that causes it to not refresh the page at all. Also, how do I un-verify myself? I’m running out of profiles to try this on and it somehow remembers that I signed in even when incognito.

Incognito on some browsers only clears data when you close the window.

Can you use dev tools to make sure the refresh is getting called at all?

I closed all the incognito windows. I’m on Firefox (so, technically, it’s a “private” window).

I could do this except now I’m verified everywhere. I might have to modify the code just to un-verify myself.

1 Like

I was wrong. There was another incognito window hiding from me. Now it resets each time.

Looking at the code:

if (selem.attributes.authed.value) {
    eval(selem.attributes.authed.value);
} else {
    window.parent.location.reload();
}

You’re not actually calling the reload function, but also that should probably just be window.location.reload();.

Just remove the authed attribute or add the reload function into the if portion of the if statement.

1 Like

But they want to reload the parent, not the original.

1 Like

Yeah but I think they’re confused because the script they are running is in the so called parent, and they are trying to call that when the popup closes.

1 Like

I don’t really know what this means.

The script is in the iframe; it’s a child. I need the child to reload the parent instead of just loading the parent within the child (thus creating an iframe within an iframe instead of just one iframe).

Yes. Once the ReplAuth popup closes, I want the parent page to refresh.

Basically, I have /upload and /upload-basic or something like that. /upload-basic is the ReplAuth webpage embedded in an iframe on /upload. I wanted the ReplAuth webpage of /upload-basic to refresh its parent page of /upload once authorized, but instead it loaded it within the iframe.

I did not find the answer to my question; however, I did solve my problem. Writing this out like this made me realize that I just needed the ReplAuth script to reload /upload-basic instead. Problem solved.

2 Likes

Mark a post as solution.

1 Like

I thought about it, but technically, though I solved my problem, I didn’t answer the question. Furthermore, people keep criticizing me for solving my own topics. I’ll do it though.

2 Likes

Ohh… I was looking in upload-basic thinking that was the actual page but now I see it’s in an iframe within upload… although having understood that now, I don’t know why you wouldn’t just have it as its own page…

2 Likes

Now understanding what you’re actually trying to do, dragonhunter1 was on the right track, it’s just that I believe opener is undefined, likely because it’s not a popup or something.

I forked your repl tested this using window.parent.location.reload(); instead and it worked fine. :slight_smile:

4 Likes

It still only works for me if I set the reload URL to /upload-basic as following your advice still doesn’t reload the parent frame. However, I no longer need to know how to do this as now I’m just reloading the embedded page instead of the whole tab. You see, since it loaded the page inside the page, I get two navbars.

image

Thanks for trying everyone!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.