0

I need to click on the button on the previous screen by clicking on the button at the current screen Writing method for clicking on the current button screen is easy (see below) but I have troubles finding the button on the previous screen.

$('body.printing').prepend('<input type="button" value="Retry" id="RetryLetter"/>');

    $("#RetryLetter").click(function()
    {
//          parent.history.back().$("#printLetter").click();
        var prButton =  document.referrer.getElementById("printLetter");
        prButton.click();
//          window.opener.$("#printLetter").click();
    });

I tried several variants – so far nothing worked

Alex
  • 7,007
  • 18
  • 69
  • 114
  • 5
    What do you mean by "current" and "previous screen"? Web pages? That's impossible... you can only interact with what exists. Before you try adventures calls such as `parent.history.back().$("#printLetter").click()` you should first read what `history.back()` is actually doing and returning: https://developer.mozilla.org/en-US/docs/DOM/window.history. – Felix Kling Dec 20 '12 at 22:38
  • But...what if that page is no longer loaded? How will you trigger a click on a page that is not (necessarily) being displayed – Lix Dec 20 '12 at 22:38
  • What do you mean previous screen? If its another page, the DOM is simply not loaded, you can't click it. – Agush Dec 20 '12 at 22:38
  • You cannot do anything on a page which is no longer loaded. also `document.referrer` returns a string so you cant use document methods on it – lostsource Dec 20 '12 at 22:38
  • Yes, I mean previous pages. parent.history.back() returns me to the previous page but clicking does not work – Alex Dec 20 '12 at 22:39
  • Yeah parent.history.back() is just a reference to the previous page, but the previous page button does not exist in the context of the new page. – Agush Dec 20 '12 at 22:41
  • @Agush: It's not a reference to anything. It makes the browser load the previous page. That's a big difference (I guess you meant that though). – Felix Kling Dec 20 '12 at 22:41
  • @anarinsky: JavaScript in one page can never affect the DOM or JS of another page (unless you load iframes from the same domain). – Felix Kling Dec 20 '12 at 22:42
  • @FelixKling you are right, bad wording on my part. It's not a reference, it just toggles the back browser behavior. – Agush Dec 20 '12 at 22:43

2 Answers2

4

document.referrer is just a string with the referring URL. It is not a DOM element that you can access.

http://wap.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_referrer

Brian Duncan
  • 1,176
  • 1
  • 13
  • 21
  • If you open up a popup window however, you can access the parent window. See: http://stackoverflow.com/questions/2167455/how-to-access-parent-window-object-using-jquery – Brian Duncan Dec 20 '12 at 22:43
  • It looks that I need to load previous page again not using history – Alex Dec 24 '12 at 19:12
0

So, it appeared that the only way to click on the button on the previous page is recreating the Get request from this button.
I memorize the request string (URL and parameters) in the session object and then repeat this request from the following page

Alex
  • 7,007
  • 18
  • 69
  • 114