Javascript Bookmarklet 获取当前 URL
如何使用可在小书签中使用的 JavaScript 代码获取当前 URL?此代码不起作用:
javascript:copy(window.location.href);
它需要将其复制到剪贴板。我需要支持 Firefox、Chrome 和 IE
How would I get the current URL with a javascript code that could be used in a bookmarklet? This code isn't working:
javascript:copy(window.location.href);
It needs to copy it to the clipboard. I need to support Firefox, Chrome and IE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以从中复制当前 URL 的对话框怎么样?
void
部分可防止浏览器在按“确定”或“取消”时导航离开。将 URL 放入剪贴板需要更多工作,并且在不同浏览器上有所不同。如果您确实想将数据放入剪贴板,请提及您需要支持的浏览器。
What about a dialog from which you can copy the current URL?
The
void
part prevents the browser from navigating away when pressing OK or Cancel.Putting the URL into the clipboard takes more work, and differs on distinct browsers. If you really want to put the data in the clipboard, mention the browsers you need to support.
要使用书签从任何合法浏览器(Opera、Chrome)获取 URL:
如果要添加页面标题:
To get the URL from any legit browser (Opera, Chrome) with a bookmarklet:
If you want to add the Page Title:
JS 中没有内置函数称为 copy。如果页面中有一个,那么它应该可以工作。
因此,该页面需要此代码
如何在 JavaScript 中复制到剪贴板?< /a>
There is no built-in function in JS called copy. If there is one in the page, then it should work.
So the page would need this code
How do I copy to the clipboard in JavaScript?