Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 4 of 4

This is a discussion on accessing localStorage from content script? within the Chrome Plugins section, part of the Google Chrome category: hi, I'm trying to build a script, and I need to access localStorage from my content script. script.js: Code: var ...


  1. #1
    mvmacd is offline Junior Member
    Join Date
    May 2010
    Posts
    5

    Question accessing localStorage from content script?

    hi, I'm trying to build a script, and I need to access localStorage from my content script.

    script.js:
    Code:
    var MAIL = localStorage.EMAIL;
    var flags = document.getElementById('flags');
    if(flags){
    document.getElementById('flags').innerHTML = prev + 
    "<a href='http://mvmacd.comlu.com/craigslist.php?user&amp;addr="+MAIL+"'>Email this</a>" 
    }
    That points to a PHP script on my server, and it uses the HTTP referrer to extract the ID of a page to mail, and uses addr to decide where to send it. The problem is, the mail variable is undefined. So I've been trying to find out how to access local storage, by searching on google, and read you have to use a sendRequest on my script.js and onRequest on my background.html, so I've tried copying and pasting from what worked for other people, but it just won't work for me!
    if you can give me a simple and straight forward example, I'd appreciate it. Thanks,
    ~Matt

  2. #2
    mvmacd is offline Junior Member
    Join Date
    May 2010
    Posts
    5

    Default

    bumpitey bump.... anybody? I really need to know this info to finish my plugin and publish it
    [though I dunno how many people will use it, somebody I know requested this plugin]
    thanks again

  3. #3
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    Not tested, just copied and pasted from....
    http://code.google.com/chrome/extens...ng.html#simple
    ...and changed a little, too tired to do more. Hope it works for ya

    contentscript.js
    ================
    chrome.extension.sendRequest({localstorage: "email"}, function(response) {
    var MAIL = response.email;
    var flags = document.getElementById('flags');
    if(flags){
    document.getElementById('flags').innerHTML = prev +
    "<a href='http://mvmacd.comlu.com/craigslist.php?user&amp;addr="+MAIL+"'>Email this</a>"
    }
    });

    background.html
    ===============
    chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
    if (request.localstorage == "email")
    sendResponse({email: localStorage.email});
    else
    sendResponse({}); // snub them.
    });

  4. #4
    mvmacd is offline Junior Member
    Join Date
    May 2010
    Posts
    5

    Thumbs up

    Thank you so much!!!!! It works

Similar Threads

  1. How to debug content script?
    By alex82 in forum Plugins Development
    Replies: 6
    Last Post: 07-21-2012, 03:45 PM
  2. content script help
    By crackruckles in forum Plugins Development
    Replies: 7
    Last Post: 02-19-2010, 04:31 AM
  3. Content Script Issues
    By hexid in forum Plugins Development
    Replies: 2
    Last Post: 12-15-2009, 03:37 PM
  4. Stuck with content script...
    By rohit in forum Plugins Development
    Replies: 1
    Last Post: 12-15-2009, 03:19 PM
  5. content script problem..
    By Gaurang033 in forum Chrome Plugins
    Replies: 0
    Last Post: 06-01-2009, 10:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •