开发者

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

开发者 https://www.devze.com 2023-02-03 20:04 出处:网络
I want to navigate through pages usi开发者_JAVA技巧ng \'Next\' and \'Previous\' buttons in my page.

I want to navigate through pages usi开发者_JAVA技巧ng '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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号