Bookmarklets, a quick follow up

Following my previous example, here is another version of the “grab a part of an external site’s page and save on my site with links to the original & page title” bookmarklet.

Updated to:

  • use an anonymous function to wrap it up
  • select and submit the underlying html, not only simple text

Most of the js code is from Tim Down’s answer on Stack Overflow

  1. copia formattato (html):
  2.  
  3. <a href='javascript:(function(){var h="",s,g,c,i;if(window.getSelection){s=window.getSelection();if(s.rangeCount){c=document.createElement("div");for(i=0;i<s.rangeCount;++i){c.appendChild(s.getRangeAt(i).cloneContents());}h=c.innerHTML}}else if((s=document.selection)&&s.type=="Text"){h=s.createRange().htmlText;}location.href="http://ferrarasociale.org/home/contents/bookmarklet?link="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)+"&intro="+encodeURIComponent(h);})()'>
  4. >> my bookmarklet html
  5. </a>

Of course, the cakephp part remains the same.
Well, it’s not even relevant if the server side receiver script is a cakephp action, or php at all.
Just do wath you want using your language or framework of choiche, with the passed data.

Enjoy!