Trying to reload parent page after opening new window from iframe

Hi,

I have a strange setup that requires an iframe which then has a link to open a new tab/window.

When someone clicks on the link I need the link open in the new tab and the parent page to reload. The reason for this is that when the page reloads it changes the message to a completed message so that when the user finishes using the new window page it closes and defaults back to this complete message.

I’ve tried a few things and am pretty close to getting it to work but just can’t get the last bit

I’m using this (not my original code)


<script>
function open_in_new_tab_and_reload(url)
{

  //Open in new tab
  window.open(url, '_blank');

  //focus to that window
  window.focus();

  //Reload the parent window
  window.parent.location.reload();

}
</script>

This is not currently working as it will open the link but not reload the page but if I change the ‘reload’ part to being first in the list it does reload the page but then doesn’t open the tab.

Any thoughts how to get it to achieve both?

thanks

Hi @Noppy, with just

window.open(url, '_blank')
window.location.reload()

it would actually open a new tab, switch to that new tab, and immediately reload the original window (tested in chrome and FF). It’s the focus() part that’s not working for me… is that what you actually want to do, switch back to the the original window right after opening the new tab? Otherwise it would be

const child = window.open(url, '_blank')
child.focus()

… but again that would be the default behaviour anyway.

Hi,

It was a bit of a weird situation so I’m not sure if it is wix that is preventing it reloading as I think wix loads iframes in a strange way.

If I try the embedded page directly it will open the new tab and reload the page correctly. It just won’t do it in an iframe from a wix page.

I’ve done a work around though that I think will work for us, instead of trying to reload the page and using PHP (hence the reload) I simply used some JS to inject some html onto the page when the link is clicked before it opens the new tab. It seems to do the job.

I’ll have a play with the code you mention out of interest and see if that will work how I was initially thinking.

Thanks

1 Like

Ah okay, thanks for the clarification! Using JS to update the content seems like a more elegant solution anyway IYAM… :-)

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