jquery and passing global variables
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.
The script environments of two different pages are entirely independent, so you cannot communicate over variables like this. Basically you have two choices:
- Use cookies.
- 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
精彩评论