0

I have two files like inject.js and PdfLogin.js. I have setting the localStorage.setItem("base64", file) in inject.js file, Now i want to get the value of the localstorage in PdfLogin.js page and i am using to get the value like this

localStorage.getItem("base64")

but it is returning "null" value.

How to send and get data from one page (mail.google.com says) to another page (An embedded page at PdfLogin.html says)???

I am using like this

localStorage.setItem("base64", file) // mail.google.com page 

and i'm getting the null value in embedded page at PdfLogin.html

localStorage.getItem("base64");

Mail ID: mahendraveeregowda@gmail.com

Mahendra
  • 317
  • 2
  • 4
  • 16
  • [The localStorage isn't per page, it's by domain](https://stackoverflow.com/questions/18709523/why-do-two-web-pages-have-different-localstorage-how-can-i-fix-this) – Mario Padilla Feb 23 '18 at 10:52
  • Content scripts of extensions can use `chrome.storage.local` – wOxxOm Feb 23 '18 at 10:58
  • Hi Mario, actually im developing chrome extension, i have written some code to inject my extension to gmail attachments(this is done), now if i click the icon on attachment , i'm getting the base64 string and there only im storing like localStorage.setItem("base64", file), and now i used to get the value in another page but its return null – Mahendra Feb 23 '18 at 11:00
  • Hi wOxxOm, Thank you so much for your help, thanks a lot sir, i'm using like this var Base64=""; chrome.storage.local.get('Base64', function (result) { Base64 = result.Base64; alert(result.Base64); });alert(Base64); here im getting the first alert message correctly, but outside the function of **chrome.storage.local.get** alert is undefined, how to use this one because i have to put the value is ajax call – Mahendra Feb 23 '18 at 11:22
  • Hi wOxxOm, how to store the value of **chrome.storage.local.get** to some variable??? like as ** var abc = localStorage.getItem("key")** alert(abc); – Mahendra Feb 23 '18 at 11:40
  • Look for examples, there are many. In short, chrome.storage is asynchronous so the value should be used only inside the callback. – wOxxOm Feb 23 '18 at 12:23
  • @wOxxOm, Thanks for your valuable guidance, its working – Mahendra Feb 23 '18 at 12:57
  • @wOxxOm, Can i get your mail ID??? – Mahendra Feb 23 '18 at 13:35

2 Answers2

0

If you are trying to store a complete file, I'm afraid you'll come back empty-handed. For as far as I know, you can only store primitive types in localStorage (e.g. integers, strings,...) and even then they are stringified.

What data are you trying to store?

0

It's not just one page, it's one domain, and that isn't going to work the way it's intended. I presume the situation is that there is a link in a page viewed in an email at mail.google.com, and it's redirecting to your site? If so, the only mechanism that works is to send the data along with the link in the URL.

Are you generating the message with the URL initially? What we used to do is encrypt data we needed and added that encrypted string to the end of the URL string. This then was the URL in the email, and the page received that just fine.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Thanks for your suggestion, i'm not generating any message with URL, i just want to send the storing value from **mail.google.com** to my site now i got the solution to send and get the valus across the web page, Thank you – Mahendra Feb 23 '18 at 13:35
  • How to open a iframe src inside the parent one like first iframe – Mahendra Mar 01 '18 at 12:01
  • I would post that as a new question, and please include any related code. – Brian Mains Mar 01 '18 at 13:14