0

I have the following:

window.linkFrom;

$(document).ready(function(){

    $("a.linker").click(function(event){

            window.linkFrom = $(this).closest("div").attr("id");

            alert(window.linkFrom); 

            });

 });

and want to pass the var linkFrom to a different script on a second page:

window.linkFrom;

(document).ready(function(){    

            alert(window.linkFrom);

});

How do I make this work?

TIA.

1 Answer 1

2

The script environments of two different pages are entirely independent, so you cannot communicate over variables like this. Basically you have two choices:

  1. Use cookies.
  2. Modify the calls to the second page to add e.g. #linkFrom=asdf to the address and parse that in the js of the second page.

Clarifying edit: scripts -> script environments

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

2 Comments

Thanks Clacke. What if I were to use the first script on both pages. Would the variable save from page to page?
No, it doesn't matter. From one page load to another the scripting environment is reset, so you need to transfer the information through a side channel, like cookies or http fragments (the right-hand side of the #).

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.