Home > Enterprise >  Reload new url using js
Reload new url using js

Time:04-17

I am opening a file on the new tab using window.open('filepath'). i want to reload the new url once it is opened.how can i achieve this? I tried the below code but the new url is not reloading once it is opened.

var newurl = window.open('filepath','_blank');
window.location.reload();
        or
window.location.reload(newurl);

edited: Actually i am opening the content of the xml file on new url. when the file is opened on new tab it contains the previous data not the updated content. it is showing the updated content only upon reloading. The updated content will be shown on my local even if i do not reload the page but in some other site.It is not working without reloading.

CodePudding user response:

let say you want to open google.com,like this

For FireFox

let tab=window.open("https://www.google.com","_blank") now to reload it you need to do something like this

tab.self.location.replace("https://www.google.com")

this will cause tab to reload the url,hope this will help

For chrome

with chrome it will only work if the script try to open the same origin URL,i.e both tab have same origin

tab.location.reload()

CodePudding user response:

You access the window of the opened window given you don't violate CORS

const newurl = window.open('filepath', '_blank');
if (newurl) { // check if null, FireFox returns null
    newurl.location.reload();
}
  • Related