开发者

How to store URL of clicked hyperlink

I am displaying a warning dialog box whenever user tries to navigate from current page without saving data on current page. Its working fine now I want to call a function (Spring controller, its kind of java function which handled URL mappings ) when user clicks on Ok (in warning dialog box) and then he should get redirectd to desired page.

Let me try to make it simple (Its confusing for me also):

  1. User is on registration page, he/she made some changes and didn't save it.
  2. Now user clicked on any other link for example he clicked on About Us link.
  3. Now I want to execute my spring controller.
  4. After execution of controller user should get navigated to About Us page.

    For this I need to save value of clicked hyperlink and pass it to my spring controller.

    So how can I store URL of clicked link (URL of About Us page in above example) ?

PS: I will really appreciate if anybody can edit my question to make it easier t开发者_Python百科o understand.


if you use jQuery, you can attach an event handler to onclick to all links in the page and once clicked the handler should save the href attribute to some variable. then create a onbeforeunload event listener on your window, where you can use the value however you want, call your controller or save the value in a cookie or something.


Are all the links on the page pointing to your spring application? If there are no external links anywhere (pointing to external resource) - then you could write a simple Filter where you can save the requested page into the session.

Otherwise, if there are links to external resources - you would need to rewrite them from www.external.com to www.my.com\MagicController?requestedPage=www.external.com. Controller will save the link and send a redirect in HTTP header to the requested page. This is a common practice - even google does that (check out the google search result links for how it will look like).

Added: Weird, but google does that only on some rare occasions, so you probably won't be able to find an example there.


Don't require to preserve the href of selected tab.Do one thing attach same javascript function with each tab and pass the "this" as parameter of function.

Function of the javascript is

function Attach(ele)  
{

// 1. Find the handle of selected tag and store in the variable. 
   ele=$(ele);

// 2. Find the value of href
   var href=ele.attr("href");

// 3. Perform server side operation you want.

// 4. redirect to another page.
   window.location=href;

  return false;

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜