简体   繁体   English

将锚链接的 href 值传递给 URL 参数

[英]Pass href value of anchor link to URL parameter

I'm looking to pass the href value of an anchor into the address bar as a parameter when clicked ie ?url=xxxx.pdf.我希望在单击时将锚点的 href 值作为参数传递到地址栏中,即?url=xxxx.pdf。 This is so it can be passed onto the next page and used in a hidden field on a form.这样它就可以传递到下一页并在表单的隐藏字段中使用。 I also need the default action on the anchor to change and direct to a different URL that contains the form with the hidden field (I can handle the form).我还需要锚点上的默认操作来更改并定向到包含带有隐藏字段的表单的不同 URL(我可以处理表单)。

So i need to:所以我需要:

  1. Click the anchor link点击锚链接
  2. Append the destination to a URL parameter Append 目标到 URL 参数
  3. Divert to the lead capture page (im guessing maybe after a couple of seconds to allow the browser time to append the url.转到主要捕获页面(我猜可能在几秒钟后允许浏览器时间到 append 和 url。

I have spent some time searching the web but can't find any info on this specific query, is anybody able to help?我花了一些时间搜索 web 但找不到有关此特定查询的任何信息,有人可以帮忙吗?

The best way will be to modify location.search property to achieve this最好的方法是修改 location.search 属性来实现这一点

 document.querySelector('#test-anchor').addEventListener('click', function(evt) { location.search = this.href; });
 <a id="test-anchor" href="url=xxxx.pdf">Test Anchor</a>

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

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