0

I want to navigate through pages using 'Next' and 'Previous' buttons in my page.

I want to do this without using forms or links.

The page can be just a html/php.

I want to know what are best ways to do this.

3
  • 1
    Without using forms or links? Is this homework? Commented Jan 13, 2011 at 10:39
  • 1
    if you need to hammer nails, use a hammer Commented Jan 13, 2011 at 11:34
  • Links (or to be more specific A (for Anchor) tags) are "just html". They are also standardised, have been part of the specification since the very beginning and are supported by absolutely everything. More importantly people know how to use them and are comfortable with them. Why wouldn't you want to use them? What are you trying to achieve? You could make it go to the next page if you, for example, move your mouse all the way to the right-hand side of the page. Whether or not you would want to is another question. Commented Jan 13, 2011 at 14:02

5 Answers 5

4

You should use links, because you can never predict what level of advanced navigation a user's browser supports.

That being said, there are a few alternatives to load a new page.

  • You could use Javascript to load a next/previous page when a button is clicked.
  • You can use <link rel='previous'> and <link rel='next'> to show Next/Previous buttons on some browsers.

But again, unless you can come up with some very good reasons, you should really use links.

Maybe you can tell more about why you don't want to use forms or links?

Sign up to request clarification or add additional context in comments.

2 Comments

I just wanted to know if I can navigate without links or forms, also I will require page redirection
There you have it, it is possible (depending on what browser and what settings you have). But you can never assume it to be possible for a random user.
1

If you want buttons in your page and make them load a new document:

<button type="button" onClick="document.location='next'">Button</button>

You could also use AJAX, or jQuery with $('body').load('next.php body') methinks.

Comments

1
    <button type="button" onclick="javascript:window.location='http://stackoverflow.com/questions/4679117/how-to-navigate-from-a-html-php-page-without-using-forms-or-links';">next</button>

Comments

0

The only way I can remember now is using something like this:

Using javascript in the button.

Comments

0

Javascript way: works pretty much like browser back and next buttons

<a href="#" onclick="javascript:history.back();">Previous</a>

<a href="#" onclick="javascript:history.forward();">Next</a>

Hope this helps.

If you don't want links then use a button instead and give it an onclick event.

For navigating between pages

<button type="button" onclick="javascript:window.location='section1.php';">next</button>
<button type="button" onclick="javascript:history.go(-1);">Previous</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.