我用鼠标突出显示以下文本:
Site: http://www.solidfiles.com
Sharecode[?]: /d/1234567890
然后使用以下小书签命令:
javascript:(function(){
var txt = window.getSelection();
txt = txt.replace('[?]', '');
txt = txt.replace('Site: ', '');
txt = txt.replace('Sharecode: ', '');
txt = txt.replace(/\n/g, '');
window.open(txt);
})();
使用 txt.replace 命令时,JavaScript 停止工作。我不知道出了什么问题。请帮忙。
最佳答案
window.getSelection()
返回 Selection object ,您需要先将其字符串化:
txt = txt.toString();
.
关于Javascript 文本搜索和替换不适用于小书签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51570813/