书签以将字符串附加到URL

时间:2018-11-11 13:40:00

标签: javascript url bookmarklet

我尝试使用书签在Chrome中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));})();

那也失败了。

有什么办法解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

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