Reputation: 42070
Suppose I have a "one page" web application. The "main page" (index.html) contains a few web forms, but only one form is displayed at any time. When the application is loaded only form A
is displayed in the page. The page contains also a button, which hides form A
and displays form B
.
Now I would like to add a new URL, which displays form B
(but not form A
).
What is the right way to do it ?
Upvotes: 3
Views: 95
Reputation: 76629
I agree with Quentin, I believe you should have multiple pages. But for your current needs you can do the following:
You give an id for all of your forms. For instance, if you have form A, form B and form C, you can give them the id of "A", "B" and "C".
In the URL you can define a GET parameter called formid, like: http://www.yourpage.something?formid="B"
All the forms should have a class, let's call that foo which is defined as:
foo { display: none; }
When the document has loaded, with Javascript read the value of the formid GET parameter , let's suppose you have that in a variable called myformid. Then:
$("#" + myformid).removeClass("foo");
Upvotes: 1
Reputation: 943696
pushState
and friends to change the URL to that of the second page Upvotes: 5