I am trying to change the content of an html page when some action on the widget is taken.
Code:
function widget(newURL) {
var server_url = "127.0.0.1:8000";
var oldHTML = document.documentElement.innerHTML;
$.post(server_url + "/convert/",
{ input_html: oldHTML, convert: newURL },
function(response) {
var resp = JSON.stringify(response);
resp = resp.substring(1, resp.length - 1);
var jObj = JSON.parse(resp);
var win = window.open(newURL,'_self');
document.write(jObj.data);
});
}
With this code, though the HTML content gets changed but the HTML page's URL doesnot change. Can someone please suggest how can i change webpage URL as well as content both ?
Updated Code:
function widget(newURL) {
var server_url = "127.0.0.1:8000";
var oldHTML = document.documentElement.innerHTML;
$.post(server_url + "/convert/",
{ input_html: oldHTML, convert: newURL },
function(response) {
var resp = JSON.stringify(response);
resp = resp.substring(1, resp.length - 1);
var jObj = JSON.parse(resp);
window.history.pushState({"html":jObj.data},"", newURL);
document.documentElement.innerHTML = jObj.data;
});
}
In the updated Code, the URL changes as well as the content. Thanks,