开发者

jquery and passing global variables

开发者 https://www.devze.com 2023-01-10 00:40 出处:网络
I have the following: window.linkFrom; $(document).ready(function(){ $(\"a.linker\").click(function(event){

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:

  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

0

精彩评论

暂无评论...
验证码 换一张
取 消