Below a javascript/jQuery function that is called when a button with class "postbit_quote" on HTML page on the screen is clicked. The id of the button is stored in the variable post, the variable thread is set to the value of a variable $tid in the php script that created the page, and the variable selected is set to the text which is selected at the moment the button is clicked. Then the $.post method is used to call a php script "newreply.php" with the variables mentioned above passed to the script. This script creates a html document that is echo'ed. Generally this is then shown as a new page that is waiting for a user response. But in this construction the echo'ed information is captured and returned to the javascript through the argument "data" of the .done function. When this variable is written with document.write, the page with the html is shown.
$(document).ready(function(){
$(".postbit_buttons").on("click",".postbit_quote",function(){
var post = this.id.substring(5);
var thread = getUrlParameter("tid");
selected = window.getSelection().getRangeAt(0).cloneContents();
$.post("newreply.php",{tid: thread, replyto: post, selection: selected}).done(function(data) {document.write(data)});
});
});
This works, that's not the problem. The problem is that when the page is shown the url in the address field of the browser is still that of the original script, and not that of the called script (here newreply.php) which is confusing. The second problem is that the indicator that a page is not finished loading (with Firefox a spinning wheel) does not stop until the page is left by some user action.
Is there a way to let the echo in the called script do it's normal job, and control is not returned to javascript?