How to make the post submitted not disappear on reload HTML - javascript

I'm working on a website, and I want the post to stay there when I reload the page. And I don't want it to disappear when I reload it.
How do I do that?

You need to use localStorage or connect to a database in the backend.
If you're a beginner, just do some research on
localStorage.

Related

Reloading page without browser knowing

I currently am building a website that fetchs data from MySQL with php and then displays it. On one of the pages I use a form to submit data and then I reload the page to display it. It does it's job fine and works exactly as I want the only problem is when a user presses the browser back button it goes through all previously submitted data instead of just going back to the page it came from. Is there a way to reload a page without the browser storing it or is there a way to make the browser go back to the previous page instead of history.
NOTE: I am aware of Ajax and how to use it to not reload the page at all but I wanted to see if there was a way to do it without redesigning my whole page with a seemingly small problem.
You can use history.replaceState in HTML5.
Another possibility appears to be
window.onpopstate = function(event) {
window.history.go(-1);
};
although I have not tried this myself.
See https://developer.mozilla.org/en-US/docs/Web/API/History_API and https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate

how to change the present url to move to its original url after a form is submitted through an iFrame

Well.. the title was not pretty clear to make you understand but couldn't think what to write. So here is the case..
I loaded a client site (say, www.aaa.com) within my site (www.mysite.com) through an iFrame. Now there is a form in the client site and when it is submitted or any action button is pressed, I want to go directly to the main url in my browser rather than everything loading in my site within the iFrame.
Currently, when I submit the form in the iFrame, though the page changes but everything happens on www.mysite.com but I want this to go to www.aaa.com
Any help will be appreciated deeply.
Thanks.
can you show the code in which triggers the redirecting?
can't you just specify it? there are many ways to do this
in php that would be a
header('location:http://www.aaa.com'); //php

How do I refresh a page in single html5 jquery mobile app

I am developing an app using jquery mobile 1.4. I have this problem that when I edit an item using an edit form, the changes is saved in the localStorage but when I visit the list view page it does not reflect unless I manually refresh the page.
My save event of the form is like this
//After the selected employees has been edited
localStorage.setItem("employees", JSON.stringify(employees)); //set the update values to localstorage
alert('Employee Updated Successfully');
$('#employees_list').listview('refresh');
$.mobile.changePage("#home_page");
So I don't refresh it manually I added
history.go(0);
The problem with history.go(0); is that after compiling with phonegap it shows a blank screen and takes quit a while when it reloads which makes it seem as if the app has crashed.
So any suggestion on how to refresh the listview page without having to reload the entire html file?
It is a single html5 page with the listview page
id = '#employee_list_view_page'.
Or alternatively set it to stop (or timeout) after some seconds so the user dont think the app has crashed.
Thanks
I noticed you are saving to the new data to the local storage, but it seems like you are not reloading the list with the new data before the refresh, thats probably why the page doesn't get updated. On top of refreshing the listview you also need to manually call the function you would normally use to load data into the listview. Make sure you call this function before calling refresh. Hope it helps!

History Sensitive Back Button

Is it possible to have a button on a webpage that will be named 'Back' and do window.history.back() if the user has navigated to the page from another page on your website and otherwise have some other title and be a direct link if the user navigated to your page from another website or went to the page directly.
Google plus on mobile seems to have this behaviour. When you click on a post in your stream then it has a 'back' button on the post page. However, if you go to the post page directly then it has a 'stream' button on the post page.
This seems tricky to implement because you don't have access to the urls in window.history.
Have you any chance of adding an ext lib like BBQ? It's a package used to manage the history behavior in your page.
I have done this before. You can do this with an anchor in the link. The anchor needs to have every get parameter of your application (i.e. application state) stored. Your application should be able to parse the anchor. To intercept the back button look here: stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript.
#benmmurphy I also had the same problem, then I used the following, which worked perfectly for me. You have to paste it on the page, from where you want to go back.
GO BACK
Hope this will help you.

When I click on Refresh button on IE my javascript getting refresh -how to stop it

I developed a website using Javascript and HTML pages
Problem :
When i am clicking on refresh button on Internet Explore, it is going to home page instead of refreshing the current page of my web page. please do the need full
Regards
Santosh
This usually happens when you are using ajax to update parts of the website after loading.
Ex: Say clicking on add button loads a form using ajax.
When you do like this the URL in the browser remains same even after loading the form. Because of this hitting the refresh button will not take you to form again.
Solution:
Really Simple History (RSH) is lightweight JavaScript library for the management of bookmarking and browser history in Ajax/DHTML applications.
Use this library to update the browser URL after the ajax request. Now the refresh should work fine.
Hope this helps.

Categories

Resources