0

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.

2 Answers 2

1

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()

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your response but its not working for me
is there any error? i have checked it in firefox not sure for chrome
updated my answer for chrome
0

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();
}

2 Comments

not working in firefox
Seems like an FF bug, I updated my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.