如何在Chrome浏览器中创建书签,该书签会弹出一个添加URL的弹出窗口?

时间:2018-10-05 15:04:38

标签: javascript google-chrome html-helper bookmarklet bookmarks

我想在Chrome中创建一个书签,单击该书签将显示用于文本输入的弹出窗口。输入该内容并附加到URL。

示例: 我要附加的网址

https://store.com/admin/tableviewer.asp?table=Discounts&IsASearch=Y&submit.search.x=search&CouponCode=

然后是一个POPUP窗口,要求输入-“甜”

结果网址

https://store.com/admin/tableviewer.asp?table=Discounts&IsASearch=Y&submit.search.x=search&CouponCode=

2 个答案:

答案 0 :(得分:0)

欢迎使用StackOverflow。

您可以使用内置的window.prompt(或仅使用prompt())功能。它使用输入打开警报,并返回您输入的值。我假设您想重定向到所需的链接,因此您可以通过将window.location设置到所需的位置来进行重定向。

看这个演示:

const word = prompt("Please enter value", "sweet");
const url = 'https://store.com/admin/tableviewer.asp?table=Discounts&IsASearch=Y&submit.search.x=search&CouponCode=';

if (word) {
  window.location = url + word;
}

答案 1 :(得分:0)

查看此支持文章以了解如何执行此操作:https://support.mozilla.org/en-US/questions/1200286

javascript:window.location = "https://mycompany" + prompt("enter string:");

相关问题