jquery, session, cache
I have a problem and I want to resolve it with jQuery.
I have a some Links on the page, and want to get the "text" from the link what was clicked. But I need this text to use on another page. Because when I click this anchor I leave this page , and I go to another one, and I need to use this "Get link text" on the second page.
I Hope it is 开发者_运维知识库possible to use browser Cookies with jquery helps ..
Can you help me, if it is possible!!
Thanks !
$("a").click(function(event){
myTarget = $(this).attr('href')+"?txt="+$(this).text();
window.location.href = myTarget;
});
This will pass the text of the link to the next page as a query string parameter called "txt".
Does that help?
How about adding the text to request parameters and using it on server side?
Read here how to set and read cookies -- then you can make the link set the cookie using onclick=""
and at the end of the onclick return true;
to make it link to where it was supposed to right after it finishes. Basically,
<a href="http://google.com" onclick="setCookie('link_title','Go to Google');return true;"> Go to Google </a>
Try the cookie plugin for jquery: http://plugins.jquery.com/project/cookie
Using the Cookie plugin:
$(document).ready(function() {
$('a.something').click(function() {
$.cookie('my_cookie', $(this).text());
});
});
// on your second page
$(document).ready(function() {
$('a.something').text($.cookie('my_cookie'));
});
精彩评论