简体   繁体   中英

How to navigate from a html/php page without using forms or links?

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.

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?

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.

    <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>

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

Using javascript in the button.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM