How to create Bookmarklet for my website which requires user authentication
I want to create a bookmarklet for my website. I just want to do same as Readitlater or as delicious. Whenever you click on Read It Later or save on delicious bookmarklet if user is not logged in, it asks user to login to continue & then save the bookmark. Otherwise if user is logged in then it directly saves the开发者_如何转开发 bookmark for user.
I want to implement exactly the same in my website & I am working on Ruby on Rails platform. I have following javascript code for bookmarklet
<a href="javascript:u=document.location.href;t=document.title; s=window.getSelection();
void(window.open('http://www.example.com/node/add/web2ob?edit[title]='+escape(t)+
'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u),
'_blank','width=600,height=500,status=yes,resizable=yes,scrollbars=yes'));">
Add to my list</a>
I am new to this stuff so please guide me. Thank you!
You have to check if the user is connected, if he is then just put your link, else, put another link which will pop up an authentication form and if he successfully sign in you'll execute your js code. Like following: (I assume you're in a rails view, so in a html.erb file)
<% if user_signed_in? %>
<a href="javascript:u=document.location.href;t=document.title; s=window.getSelection();
void(window.open('http://www.example.com/node/add/web2ob?edit[title]='+escape(t)+
'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u),
'_blank','width=600,height=500,status=yes,resizable=yes,scrollbars=yes'));">
Add to my list</a>
<% else %>
<a onclick="showLoginForm();">Add to my list</a>
<% end %>
精彩评论