Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have created an option that by clicking on span text shows or hides the sidebar. how to remember user selection after reloading page that the sidebar page was shown or hidden depending on the user's choice?
Once you refresh the page, everything that is not stored somewhere, for example a database, will be lost.
The easiest approach would be to save user's selection to his browser's localStorage.
So, after setting the sidebar to whatever state you want, you can save it like this:
localStorage.setItem('showSidebar', true); // or false
and then, when the page is reloaded, you can get the data like this:
var showSidebar = localStorage.getItem('showSidebar') || false;
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Now this added class by onclick is removed after site refresh or when going into subpage. What line is neccessary in my script to have this class remained active during browser session ?
<script type="text/javascript">
function myFunction()
{
document.getElementById('box').setAttribute("class", "contrast");
}
</script>
When you add some classes or elements to your page with JS, it will disappear when you refresh the page, or close/reopen it. It's normal behaviour.
To store information for a longer periods of time, you can use localStorage or sessionStorage:
sessionStorage.setItem will be cleared only when you close the browser, and
localStorage.setItem will store information "forever".
Here is introduction articles:
sessionStorage
localStorage
To store some information, use this:
sessionStorage.setItem('key', 'value');
Then, when your page is loading, you can read stored value and add appropriate class:
var data = sessionStorage.getItem('key');
if (data) {
document.querySelector(yourselector).className = 'yourclass';
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to figure out how to use a querystring with a page I created. Currently my page has a navigation menu that updates the div contents dynamically when you click a link. The navigation menu consists of a bunch of product categories (tomatoes, olive oils, etc).
My problem is that since these are not actual HTML pages, how can I set up a querystring to be able to link to a certain category from a completely different page.
Example:
Landing: products.html
Click 1: products.html?tomatoes
Click 2: products.html?oliveoil
You should use window.location.hash, and instead of using a ? you should use a # to split the querystring from the filename. So if you have products.html#oliveoil then window.location.hash will be #oliveoil. You will also be able to set the hash with window.location.hash = 'What-you-want'.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
What i basically want to do is to log in a user and make a new page for every user with its own personal details.
So for example user A signs in, he would have a different view than user B.
I am using javascript ans firebase for back end.
How can i make that happen?
A rough idea would be enough.
You should use Sessions for each user and one the bases of Session value you must populate values for the user each user will have seperate details and each user will have different data page will be same but data will be different so user feels that he has a new page
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to make a website where the user needs to pick one image from a selection presented on the site. When the user selects a picture, i.e. clicks on it, I somehow need to retrieve the name/ID of the selected photo, and have this available on the server.
This is because I must run a bash script on my server, with the selected image ID as input.
What is the simplest way this can be achieved?
Here's how to find the id of the element you clicked ...
$(document).ready(function() {
$(".some-image").click(function(event) {
// do something with the image id below
console.log(event.target.id);
});
});
Copied almost entirely from this stack-overflow question/answer here
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to pass variables from a button to an input form on another page.
For example,
The user clicks a button with the package they want, the button loads the next page and fill out the form with the package information they have selected. What is the best way to go about this? I am designing the website using Joomla.
Thanks,
Ed
I can suggest you to use localStorage to get this done.
localStorage.setItem('testObject', value);
then get it on other page like this:
var retrievedObject = localStorage.getItem('testObject');
then set the text field with retrievedObject .
see this post to get better idea:Storing Objects in HTML5 localStorage