Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1686 How can I generate a page in JavaScript when a button is pressed that both replaces the current page in the browser's history, and cannot be linked to directly?

irt.org | Knowledge Base | JavaScript | Link | Q1686 [ previous next ]

Q1686 How can I generate a page in JavaScript when a button is pressed that both replaces the current page in the browser's history, and cannot be linked to directly?

Try the following which allows pages to be defined in JavaScript, and then loaded when a button is pressed:

<html>

<head>

<script language="JavaScript"><!--
function page1() {
  return '<html><body>Hello world (1)</body></html>';
}

function page2() {
  return '<html><body>Hello world (2)</body></html>';
}

function nextpage(page) {
  if (!document.image) {
    location.replace('javascript:page' + page + '()');
  }
  else {
    location.href = 'javascript:page' + page + '()';
  }
}
//--></script>

</head>

<body>

<form>
<input type="button" value="Next page 1" onClick="nextpage(1)">
<input type="button" value="Next page 2" onClick="nextpage(2)">
</form>

</body>

</html>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.