Skip to content

Instantly share code, notes, and snippets.

@ethertank
Created December 10, 2012 10:42
Show Gist options
  • Save ethertank/4249887 to your computer and use it in GitHub Desktop.
Save ethertank/4249887 to your computer and use it in GitHub Desktop.
Bookmarklet: LinkToThisPage
<ul>
<li>Bookmarklet: <a href="javascript:(function(){var%20a=document.createElement(%22a%22),u=location.href,t=document.title||u,e=(function(){var%20map={'<':'&lt;','>':'&gt;','&':'&amp;','%22':'&quot;'},r=function(s){return%20map[s];};return%20function(S){return%20S.replace(/<|>|&|%22/g,r);};})(),t=e(t);a.href=e(u);a.title=a.innerText=t;prompt(t,a.outerHTML);})();">リンクタグ生成-ethertank-20121211</a></li>
</ul>
<!--
「閲覧中のページへのリンクを作成」
属性: href, title
以前作ったものはエスケープがなく問題が出たので再作成。引用符が多くて鬱陶しかったので構造も変えた。
作り直すのが面倒だったので再作成前に Web 検索したが、同種のブックマークレットの殆どに同じ問題が有ったので結局自作。
document.title が存在しない場合(PDF などの場合)、URL 文字列をタイトルの代替とする。
また改善案が出たら直す。document.title が無い時に [PDF] って文字列を突っ込むとかどうかなとか色々考えたけど、
もうちょいちゃんと練ってから追加する。とりあえずこれでいいわ。
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment