简体   繁体   English

使用JavaScript捕获重定向URL

[英]Catch Redirect URL with Javascript

Is there a way to detect the redirect url of your mvc page when a button is pressed so that you can display this url through javascript. 当按下按钮时,有没有一种方法可以检测您的mvc页面的重定向URL,以便您可以通过javascript显示此URL。

For example. 例如。 A button is pressed that will redirect from localhost:1772/tasks to localhost:1772/tasks?actionname=StockReq. 按下一个按钮,该按钮将从localhost:1772 / tasks重定向到localhost:1772 / tasks?actionname = StockReq。

Catch the localhost:1772/tasks?actionname=StockReq redirect url in var redirecturl and show an alert("redirecting to: " + redirecturl). 在var redirecturl中捕获localhost:1772 / tasks?actionname = StockReq重定向URL并显示警报(“ redirecting to:” + redirecturl)。

I think you may have a better way. 我认为您可能有更好的方法。 if you are aware of your rendered button, you may append a property (data-targeturl) where you will generate inside the full URL of your link/button, and by using a simple javascript code, you can capture the click event, read the property from the clicked link/button, and show it by your desired way. 如果您知道呈现的按钮,则可以添加属性(data-targeturl),在该属性中将在链接/按钮的完整URL内生成该内容,并使用简单的javascript代码,您可以捕获click事件,阅读点击链接/按钮中的“属性”,并以您希望的方式显示它。

also you may note that most fo the time you would end up with anchors when trying to render actionlinks (which is the MVC way to render a control that leads to another action/page inside your solution) so you can simply read the href property and do the same. 您可能还会注意到,大多数情况下,当您尝试呈现操作链接时(以MVC方式呈现可导致解决方案中的另一个操作/页面的控件的方式),最终都将以锚点结束,因此您只需阅读href属性和照着做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM