Why doesn't the localStorage work?

I have a page of my personal wallpaper thumbnails. Click on a thumbnail and the JS saves the info to localstorage, opens another page, and populates with localstorage. The image is ready to download using your smartphone screengrab feature. Click/tap on the image and it takes you to the previous page of thumbnails. That all works in the smartphone.

Why doesn’t it work on the PC? Console doesn’t have any error messages.

The image-grabbing script:

<script>
function grabFilename(filename) {
	var filename = filename; 
		localStorage.setItem('wpName', filename); // name of wallpaper file
	var mainFolder = "0trucks/0other-trucks"; // folder containing images
		localStorage.setItem('wpMainFolder', mainFolder);
	var mainHtml = "/0other-trucks.html"; // this page of thumbnails, in above folder
		localStorage.setItem('wpMainHtml', mainHtml);
	window.location = "../../wp_Show.html"; // open this page to display wallpaper
}
</script>

A sample thumbnail div:

		<div class="tile">
			<a href="#" onclick="grabFilename('truckname_768x1024')">
				<img src="../../../thumbs/truckname_768x1024.png" alt="truckname"/><div class="title">truckname</div>
			</a>
		</div>

The page that opens to display the image:

<body>
<div id="output"></div>

<script>	
	var mainHtml = localStorage.getItem('wpMainHtml'); // return to this page
	var folder = localStorage.getItem('wpMainFolder'); // folder containing images
	var image = localStorage.getItem('wpName'); // name of wallpaper file
	var output = document.getElementById("output");	// output to here

	output.innerHTML = "<a href='" + folder + mainHtml + "'><img alt='' src='" + folder + "/" + image + ".jpg' width='100%' /></a>";

</script>
</body>

I tried your code and it seems to be working. See https://www.screencast.com/t/O8yUHYDbfSx

1 Like

Hi @WebSteve, does the data actually get written to the local storage? You can check this in the “Application” tab (chrome) / “Storage” tab (FF) of your browser dev tools… just to rule out that you have some privacy settings and / or add-ons preventing local storage access.

(x-post)

The wallpapers don’t show up in Firefox but they do in Chrome and Edge. It works in MSIE after a fashion, though it ruins the thumbnail layout.

I am accessing my work desktop from a laptop at home; and the desktop is getting the files over the network, not locally.

It’s a Firefox issue. I will look into Firefox localStorage issues.

I didn’t manage to reproduce your issue on the Firefox, I also tried under “InPrivate” mode it worked fine.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.