开发者

How to reload a html page partially

开发者 https://www.devze.com 2023-04-06 09:23 出处:网络
In my web page I have a slider bar, few check boxes, radio buttons etc, which are common across 开发者_高级运维pages. When I navigate from this page I want to preserve the position of the slider bar a

In my web page I have a slider bar, few check boxes, radio buttons etc, which are common across 开发者_高级运维pages. When I navigate from this page I want to preserve the position of the slider bar and other options. How can I acheive it?


Presumably they're part of a form used to gather input — I'd have thought you want to submit this form to a specified action, which you define in your PHP to save the values in a database.

Then when each page loads you query the database for the relevant values and bob's your uncle.

If my answer sounds vague, it's because the question is quite vague — if you're new to web development I think you'll do best to find a good book / tutorial on PHP if that is what you're using.


You could either save the positions and options of the elements in a cookie and set the position of the elements on each page

or you could use an html5 iframe to load the page you are navigating to.


Best approach is using cookies to store the state of the controls you want to keep across page requests, this is perfectly achievable with javascript.

Presuming the contols are form elements:

  1. listen to the change event of each control
  2. when a change occurs save the new state in a cookie
  3. when you (re)load the page check for the existence of a cookie
    1. When it exists, read it
    2. restore the state of the control with the data from the cookie

This seems/is very simplistic but should be not to hard to implement.

PPK has a good (vanilla javascript) intro to cookies or if you are using jquery there is the excellent cookie plugin.

0

精彩评论

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