<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blogx10 &#187; Javascript</title>
	<atom:link href="http://www.blogx10.co.uk/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blogx10.co.uk</link>
	<description>Another minnow in a huge pond...</description>
	<lastBuildDate>Wed, 09 Jan 2008 17:51:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>A Working Javascript Back to Previous Page Link</title>
		<link>http://www.blogx10.co.uk/a-working-javascript-back-to-previous-page-link-4</link>
		<comments>http://www.blogx10.co.uk/a-working-javascript-back-to-previous-page-link-4#comments</comments>
		<pubDate>Tue, 11 Sep 2007 12:29:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.blogx10.co.uk/?p=4</guid>
		<description><![CDATA[In a recent project, I wanted to mimic the &#8216;back&#8217; button of the browser using an on page link. Replicating browser functions and unnecessary javascript are usually things you should avoid, but this was a special case. These were single pages that needed to be accessed from several different sections of a site and the [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project, I wanted to mimic the &#8216;back&#8217; button of the browser using an on page link.</p>
<p>Replicating browser functions and unnecessary javascript are usually things you should avoid, but this was a special case. These were single pages that needed to be accessed from several different sections of a site and the &#8216;back to previous page&#8217; link helped to keep the on-page navigation logical.</p>
<p>The problem was, I couldn&#8217;t find a version of the code which worked consistently across browsers. I tried a number of combinations such as <code>javascript:history.go(-1);</code> and <code>history.back();,</code>  in the href attribute, onclick event or in an external function, but many didn&#8217;t work at all or behaved differently in different browsers.</p>
<p>After wading through several search results pages listing other people with the same problem, Google provided a solution: <a href="http://www.irt.org/script/911.htm">www.irt.org/script/911.htm</a>. It seems to work well (tested in FF 1.5 and IE 6).</p>
<p><strong>The Solution: </strong></p>
<p>Add the following code to a HTML page:<code>&lt;a href="go-back-javascript-error.htm" onClick="this.href='javascript:GoBackLink()'" title="Go back to the previous page"&gt;« Go Back&lt;/a&gt;</code></p>
<p>(go-back-javascript-error.htm is a page that will be shown if the javascript doesn&#8217;t work. It explains that the user should use the back button instead.)</p>
<p>Add the following code to the javascript file:</p>
<p><code>// go back to previous page function</code><br />
<code>function </code><code>GoBackLink</code><code>() {</code><br />
<code>history.back();</code><br />
<code>}</code></p>
<p>I don&#8217;t know why this particular code works in an external function. Maybe a passing javascript expert will be kind enough to leave a comment to explain&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blogx10.co.uk/a-working-javascript-back-to-previous-page-link-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

