webdev
(5,250 views)

Navigating with Javascript and Php

 

To go back to previous page (same as pressing the back button on your browser)

<a href="javascript:history.back()">Cancel</a>

To go back more than one page (e.g. 2 pages):

<a href="javascript:history.go(-2)">Return</a>

To close this window

<a href="javascript:window.close()">Close this window</a>

Both together:

    <xar:comment>Allow back if there's a place to go, else Close window</xar:comment>
<p>
<script language=javascript type="text/javascript">
<!--
if (history.length > 1) {
document.write( '<a href="javascript:history.back();"><xar:mlstring>or back to previous page</xar:mlstring></a>' );
} else {
document.write( '<a href="javascript:window.close()"><xar:mlstring>or close this window</xar:mlstring></a>' );
}
-->
</script>
</p>

If you want to go back, but need to refresh the page you came from, you can use this (in Xaraya template)

<a href="$_SERVER['HTTP_REFERER'']">Done</a>

 

 

Comments

New Comment

markdown formatting permitted