= 0) { -6ren">
gpt4 book ai didi

Javascript 书签 If-Else

转载 作者:行者123 更新时间:2023-11-30 06:01:11 28 4
gpt4 key购买 nike

我正在尝试编写一个小书签来检测用户是否在已解析的页面上,如果他不在,则应将值传递给 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;
}

Bookmarklets的教程一般很少,但是我找到了这个转换工具: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;

我做错了什么?

最佳答案

这应该适合你:

javascript:(function(){if(location.href.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;}})();

请注意,我稍微更改了 if 语句以使其更健壮。

关于Javascript 书签 If-Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8493606/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com