0

I think the title is clear enough. Here is my code :

var page = document.location.href;
var site = page.split('.');
var creation=0; 

if (site[1]=='youtube' && creation == 0 ) 
{
    sessionStorage.setItem("link",page);
    var link=sessionStorage.getItem("link");
    alert(link);
    window.open('http://youtube-free.fr')
    creation=1;

}
if (site[1]=='youtube-free') 
{   
    var link=sessionStorage.getItem("link");
    alert(link);                
    document.getElementById('input').value = link;
}

The problem is that on the second page the alert return "null"... Here is my manifest :

   "manifest_version": 2,
   "name": "Free-Watch",
   "description": "This extension allow to see videos.",
   "version": "1.0",
   "options_page":"options.html",
   "permissions": ["tabs","storage"],
   "content_scripts": [ {
        "js": [ "script.js" ],
        "matches": [ "http://*/*" ],
        "run_at": "document_end"
    } ]

Thanks for your help and forgive my english.

Melki
  • 579
  • 2
  • 5
  • 26
  • 3
    Don't use `sessionStorage`, but the asynchronous [`chrome.storage`](https://developer.chrome.com/extensions/storage.html) API. – Rob W Apr 10 '13 at 16:38
  • Thanks a lot it works, but the documentation is not the better I've seen... – Melki Apr 10 '13 at 16:59
  • The documentation provides some [sample code](https://developer.chrome.com/extensions/storage.html#samples). I have also written several answers on the subject, for example this one: http://stackoverflow.com/a/15875798/938089. You can also search on Stack Overflow for existing posts about `chrome.storage`: http://stackoverflow.com/search?q=[google-chrome-extension]+chrome.storage – Rob W Apr 10 '13 at 17:02
  • Yep it's much better with the sample. – Melki Apr 10 '13 at 17:08

1 Answers1

0

I did what Rob W suggested and it work. https://developer.chrome.com/extensions/storage.html

Melki
  • 579
  • 2
  • 5
  • 26