简体   繁体   English

Javascript Booklet复制URI / URL

[英]Javascript Bookmarklet Duplicating URI / URL

I have the following bookmarklet: 我有以下书签:

javascript:findlink=document.getElementsByClassName(%22download_link%22)[2].href;window.open('https://myfiledrive.com/users/files/add?url='+findlink,'_blank');void(0);

Example: 例:

<a class="download_link" href="example.com/pdf1.pdf">
<a class="download_link" href="example.com/pdf2.pdf">
<a class="download_link" href="example.com/pdf3.pdf">

Basically, it searches the currently active page, for the third iteration of an tag with the class "download_link", and stores it in the variable "findink", 基本上,它会在当前活动页面中搜索类“ download_link”的代码的第三次迭代,并将其存储在变量“ findink”中,

Then it loads ' https://myfiledrive.com/users/files/add?url= '+findlink 然后加载' https://myfiledrive.com/users/files/add?url='+ findlink

In the above example it should load: 在上面的示例中,它应该加载:

https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf

but what ends up happening is that this gets loaded: 但是最终发生的是,这被加载了:

https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf?url=example.com/pdf3.pdf https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf?url=example.com/pdf3.pdf

  • so basically it's duplicating url= 所以基本上是在复制url =

What am I doing wrong? 我究竟做错了什么? Thanks. 谢谢。

The url param shouldn't be duplicated. url参数不应重复。 You're not appending to findlink or anything. 您没有追加到findlink或其他任何内容。 You can try the snippet below, it's exactly as you've posted. 您可以尝试下面的代码段,它与您发布的内容完全相同。

Chrome will block the popup, but if you read the error message, there's no duplication going on: Chrome将阻止弹出窗口,但是如果您阅读错误消息,则不会重复:

Blocked opening ' https://myfiledrive.com/users/files/add?url=https://stacksnippets.net/example.com/pdf3.pdf ' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set. 阻止在新窗口中打开“ https://myfiledrive.com/users/files/add?url=https://stacksnippets.net/example.com/pdf3.pdf ”,因为该请求是在其“未设置allow-popups的权限。

url is only in there once no matter how many times I click. 无论点击多少次, url都只会出现一次。

 <a class="download_link" href="example.com/pdf1.pdf">1</a> <a class="download_link" href="example.com/pdf2.pdf">2</a> <a class="download_link" href="example.com/pdf3.pdf">3</a> <a href="javascript:findlink=document.getElementsByClassName(%22download_link%22)[2].href;window.open('https://myfiledrive.com/users/files/add?url='+findlink,'_blank');void(0);">download</a> 

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

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