Hello.

Tell me how to implement the condition in the link via html. For example, there is one page example.html. It is necessary that when you open on the page there was some kind of an inscription and the edit button. When you click on this button, another page should open, not even another one, but the same one (there should be only one file), but already on this page there should be a form with an input field and a save button that saves text from the form and throws it on "first" page, where there should be a new text, which is entered into the form and the edit button. And this should be done only through the condition in the url, for example, ya.ru/example.html?edit=true.

  • Add the javascript meta as needed. Although there is a dirty hack: html5 attribute contenteditable <p contenteditable = "true"> I can edit </ p> - Sergiks
  • @Sergiks, thanks! But I would like to through the conditions url :) - compl
  • Hint: In JavaScript, the window.location.search property contains the entire GET request string, starting with a "?". For example for site.ru/page.html it will be an empty string, and for site.ru/page.html?edit this is "? edit". - Sergiks

1 answer 1

For example, so, although this is a terrible curvature:

 <!DOCTYPE html> <html lang="Ru"> <head> <meta charset="utf-8"> </head> <body> <div id="container"></div> <script type="text/template" id="page1"> <p>Это просто такая первая страница</p> <form> <input type="hidden" name="page" value="2"> <input type="submit" value="Нажми!"> </form> </script> <script type="text/template" id="page2"> <p>Вторая страница, фарш и фрикадельки!</p> <form> <input type="hidden" name="page" value="1"> <input type="submit" value="Не нажимай!"> </form> </script> <script> var el = document.getElementById("container"); switch(window.location.search){ case "?page=2": el.innerHTML = document.getElementById("page2").innerHTML; break; case "?page=1": default: el.innerHTML = document.getElementById("page1").innerHTML; break; } </script> </body> </html> 
  • Thanks, I will try! - compl
  • @Sergiks, a question appeared: what does hidden do here? After reading, I realized that this is a hidden field that contains information that is not visible to the user. But how is hidden used in this code? - compl
  • @compl when you click on a button, the form is sent using the GET method All its fields follow the question mark: Page.html? Field1 = Value1 & Field2 = Value2 & .. FieldN = ValueN In our case, this is a hidden field and carries the name "page" and the value is either 1 or 2, which ultimately gives страница.html?page=1 or page.html страница.html?page=2 - Sergiks
  • @Sergiks, thanks, understood. - compl