如何存储单击的超链接的URL [英] How to store URL of clicked hyperlink

查看:162
本文介绍了如何存储单击的超链接的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户尝试从当前页面导航而不在当前页面上保存数据时,我都会显示一个警告对话框.现在它可以正常工作了,当用户单击Ok(在警告对话框中),然后他应该重定向到所需的页面时,我想调用一个函数(Spring控制器,该类Java函数处理URL映射). 让我尝试使其变得简单(这也让我感到困惑)
1)用户位于注册页面上,他/她进行了一些更改,但没有保存.
2)现在,用户单击了任何其他链接,例如,他单击了About Us链接.
3)现在我要执行我的弹簧控制器.
4)执行控制器后,用户应导航到About Us页面.
为此,我需要保存单击的超链接的值,并将其传递给我的spring控制器.
那么,如何存储单击链接的URL(上例中的About Us页面的URL)?

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:如果有人可以编辑我的问题以使其更易于理解,我将不胜感激.

PS: I will really appreciate if anybody can edit my question to make it easier to understand.

推荐答案

如果使用jQuery,则可以将事件处理程序附加到onclick页面上的所有链接上,一旦单击该处理程序,应将href属性保存到某个变量中.然后在窗口上创建onbeforeunload事件侦听器,您可以在其中使用所需的值,调用控制器或将值保存在Cookie或其他内容中.

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.

这篇关于如何存储单击的超链接的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆