0

I have a page with button to perform print action. Here in this case , on click of the button, I want to open a new tab with a modification in the url without reloading the page.

Here is the code that I am calling on click of the button.

function changeUrl(){
 var printurl = 'https://www.example.com/mytest/print/1022/United-Arab-Emirates/2018/Guide-on-VAT-treatment-of-insurance-issued?lang=en&dir=ltr'
 var path = '1022/United-Arab-Emirates/2018/Guide-on-VAT-treatment-of-insurance-issued'
        var b = url.substring(0,url.indexOf('mytest'));
        var newurl = b +'print/' + articlepath + '?lang=en&dir=ltr';        
        window.open(printurl,"_blank");
        history.pushState(null,null,newurl);

}

Can anyone help me here to fix this issue?

santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
  • Possible duplicate of [Updating address bar with new URL without hash or reloading the page](https://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page) –  Oct 04 '18 at 19:40

1 Answers1

0

This is not working in the most modern browsers but you might give it a try:

window.history.pushState("object or string", "title", "/my-new-url");

Note: You can use relative paths with these functions as well (e.g. ../new-url or ../../new-url. Working for me with a older version chrome.

  • I tried the function mentioned in my question and my chrome version is Version 69.0.3497.100. On click of the button it opens a new tab but the url is not changing. Do you think is there any issue with the code. Can you please correct me in this case. – santosh kumar patro Oct 04 '18 at 19:46