TL;DR
What is the best way to change a page's <title>
tag when a link is clicked but page content is not re-loaded (simply shown/hidden via CSS)? Some JavaScript, I would assume?
On this page (http://www.ukipme.com/pub-marine.php) I have two methods for viewing individual magazines. Clicking on the magazine cover on the right completely re-loads the page with a query string (e.g. ?mag=1
) appended to the URL and we have set the <title>
tag to change then, but this was additional functionality we added via PHP. The framework's original method of changing content was simply to change shown/hidden content via CSS (basic JavaScript to add and remove an active
class) by clicking on the left-hand tabs.
However, I would like for the page title to change when these left-hand tabs are clicked, also. The HTML code for the tabs is as follows:
<ul class="tab-nav three columns">
<li class="active" ><a href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">Electric & Hybrid Marine</a></li>
<li><a href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">Marine Catering</a></li>
<li><a href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">Marine Maintenance</a></li>
<li><a href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">Shipping Port</a></li>
<li><a href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">ALL TITLES</a></li>
</ul>
And for their content:
<div class="tab-content nine columns">
<div class="row">
<div class="twelve columns">
<a href="?mag=1"><img src="../img/covers/evm.jpg" alt="Electric & Hybrid Marine" style="margin: 0 10px 10px 0;" /></a>
<a href="?mag=2"><img src="../img/covers/mci.jpg" alt="Marine Catering" style="margin: 0 10px 10px 0;" /></a>
<a href="?mag=3"><img src="../img/covers/mmi.jpg" alt="Marine Maintenance" style="margin: 0 10px 10px 0;" /></a>
<a href="?mag=4"><img src="../img/covers/spi.jpg" alt="Shipping Port" style="margin: 0 10px 10px 0;" /></a>
</div>
</div>
</div>
I tried investigating, and I think something needs to happen in the DOM
, but my JavaScript knowledge is unfortunately, almost completely non-existent. Can anyone kindly help?
EDIT:
I've tried changing my <a>
tags to the following, but this doesn't seem to do anything:
<a onclick="window.document.title='<?=$title?> | UKIP Media & Events'" href="#" class="skip" gumby-goto="#top_of_page" gumby-offset="-60"></a>
($title
is a PHP variable set on page load)
SECOND EDIT @MGA
My link now looks like so:
<a href="#" onclick="changetitle()" class="skip" gumby-goto="#top_of_page" gumby-offset="-60">
With this script at the bottom of the page:
<script type="text/javascript">
function changetitle() {
document.title = "<?=$title?> | UKIP Media & Events";
}
</script>
But still nothing happens?