我正在尝试编写一个书签小程序,用于检测用户是否在已经解析的页面上,如果不是,则需要将值传递给API。
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;
我做错了什么?