2011-12-13 8 views
2

사용자가 이미 구문 분석 된 페이지에 있는지 여부를 감지하고 값이 아닌 경우 API에 전달해야하는 북마크릿을 작성하려고합니다. 이자바 스크립트 북마크 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;

내가 뭘 잘못하고 있니?

답변

1

이 당신을 위해 작동한다 : 내가 만약 문장을 변경

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;}})(); 

공지 사항이 약간 더 강력하게.

+0

감사합니다. 더블을 작은 따옴표로 바꾸기 만하면됩니다. – mmackh

0

먼저 공백을 모두 제거하는 것이 좋습니다. 나는 그것이 당신의 문제인지는 모르겠지만, 적어도 북마크는별로 못생긴 것입니다.

관련 문제