【问题标题】:Bookmarklet to append a string to a URL用于将字符串附加到 URL 的书签
【发布时间】:2019-04-14 09:58:50
【问题描述】:

我尝试使用书签在 Chrome 中 URL 的开头插入链接。我希望 URL 更改为:

https://raw.githubusercontent.com/kguidonimartins/csv_example/master/1946_proposicoes.csv

收件人:

chrome-extension://ibfcfelnbfhlbpelldnngdcklnndhael/viewer.html?url=https://raw.githubusercontent.com/kguidonimartins/csv_example/master/1946_proposicoes.csv

我把它放在书签的 URL 字段中:

javascript:location=location.href.replace(location,"chrome-extension://ibfcfelnbfhlbpelldnngdcklnndhael/viewer.html?url=" + location)

但这失败了。然后,我尝试了这个:

javascript:(function(){window.open('chrome-extension://ibfcfelnbfhlbpelldnngdcklnndhael/viewer.html?url='+encodeURIComponent(location.href));})();

那也失败了。

知道如何解决这个问题吗?

【问题讨论】:

  • 抛出什么错误?
  • 没有错误。当我点击书签时,它只是不会更改 URL。

标签: javascript url bookmarklet


【解决方案1】:

试试这个代码:

javascript:(function() {
    location.href = "chrome-extension://ibfcfelnbfhlbpelldnngdcklnndhael/viewer.html?url=" + location.href;
})();

【讨论】:

  • 没有任何改变。还有更多,每次单击时,javascript 控制台都会显示以下消息:Blocked script execution in 'raw.githubusercontent.com/kguidonimartins/csv_example/master/…' because the document's frame is sandboxed and the 'allow -scripts' permission is not set. I在终端中运行google-chrome --args --allow-scripts 后也尝试过,没有任何改变。
  • 不幸的是,我不知道如何解决这个问题。也许这些限制是无法克服的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-11
  • 2014-04-25
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多