I recently added a “link to this page” toy to www.anta.net. Using JavaScript and the Apache mod_include module, the widget implements a text pseudo-input containing the exact HTML code required for creating a link to the page in question.
Of course most web page owners will know how to make links, but it probably does not hurt to make a specific suggestion while simultaneously facilitating the process.
The basic idea behind the widget is a no-brainer, but since I had to sit down for a moment to entitize and escape stuff, I will share the snippet; hopefully someone who stumbles across this page will find it amusing, or even useful.
In the presence of JavaScript support, the document title is inserted; else, the domain name of the server is used as anchor text. On the server side, the widget requires Apache with mod_include. It could probably be developed to depend entirely on JavaScript, or, on the other hand, to also grab the page title using some server-side technique. Still, this is what I whipped together:
<script type="text/javascript">
document.write('\<div\>Link to this page\: \<input type\=\"text\" size\=\"80\"
maxlength\=\"160\" value\=\"\&\#60\;a
href\&\#61\;\&\#34\;http\&\#58\;\&\#47\;\&\#47\;
<!--#echo var="SERVER_NAME" --><!--#echo var="REQUEST_URI" -->
\&\#34\;\&\#62\;' + document.title +
'\&\#60\;\&\#47\;a\&\#62\;\"\>\<\/div\>');
</script>
<noscript>
<div>Link to this page: <input type="text" size="80"
maxlength="160" value="<a
href="http://
<!--#echo var="SERVER_NAME" --><!--#echo var="REQUEST_URI" -->
"><!--#echo var="SERVER_NAME" -->
</a>"></div>
</noscript>
The above snippet has been escaped and wrapped, and is therefore unlikely to work as is. If you want to use the code rather than read it, please download it as a text file.
The "link to this page" widget by Thor Kottelin is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 1.0 Finland License. Based on a work at blog.anta.net.As always, your comments and suggestions are welcome.
Post a Comment