我正在尝试编写一个小书签,用于检测用户是否在已解析页面上,如果他不是值,则应将其传递给API。Javascript Bookmarklet If-Else
if (window.location.indexOf("thequeue.org") >= 0) {
alert("Drag the Bookmarklet in your Brookmarks Bar!");
} else {
location.href = 'http://thequeue.org/r?id=' + encodeURIComponent(location.href) + '&title=' + document.title;
}
上有一般小书签几个教程,但我发现这个转换工具:http://jasonmillerdesign.com/Free_Stuff/Instant_Bookmarklet_Converter,这给了我这样的:
javascript:(function(){if(window.location.indexOf(%22queue.org%22)%20%3E%3D%200)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert(%22your%20url%20contains%20the%20name%20franky%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0Alocation.href%3D'http%3A%2F%2Fthequeue.org%2Fr%3Fid%3D'%2BencodeURIComponent(location.href)%2B'%26title%3D'%2Bdocument.title%3B%0A%7D}());
然而,书签停止工作完全。我可以确认这是有效的:javascript:location.href='http://thequeue.org/r?id='+encodeURIComponent(location.href)+'&title='+document.title;
我在做什么错?
谢谢,工作很棒!我只需要将双引号改为单引号。 – mmackh 2011-12-13 18:08:52