Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3485354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:53:51+00:00 2026-05-18T10:53:51+00:00

Im currently trying to save the tab.url into html5 local storage when the programme

  • 0

Im currently trying to save the tab.url into html5 local storage when the programme loads then update a css file into the header based on a rule, which are all easy to do. But for some reason the popup.html loads the previous local storage variable and not the recent one.

I was wondering if anyone can help me on this, the code that im using is this;

<script language="javascript">
var rule;
var links;
var search;

function loadcssfile(filename, filetype)
{ 
   if (filetype == "css")
   {   
       var fileref=document.createElement("link");
       fileref.setAttribute("rel", "stylesheet");
       fileref.setAttribute("type", "text/css");
       fileref.setAttribute("href", filename);
   }

   if (typeof fileref != "undefined")
   {   
       document.getElementsByTagName("head")[0].appendChild(fileref);
   }
}

function loaded()
{   
    chrome.tabs.getSelected(null,function(tab) 
    {   
        var temp;
        temp = tab.url;
        localStorage['tab'] = temp;
        console.log(temp);
    });

    links = localStorage['tab'];
    rule = localStorage['ok0'];
    search = links.indexOf(rule);

    if(search != -1)
    {   
        loadcssfile("./css/styles.css","css");
        loadcssfile("./button/styles2.css","css");
    }
    else
    { 
        // or load other css file 
    }
}

document.getElementById('datacontent').innerHTML = rule + "<br>" + links + "<br>" + search;


function createXMLHttpRequest()
{ 
    if (window.ActiveXObject)
    {   
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {   
        xmlHttp = new XMLHttpRequest();
    }
}

function createXMLHttpRequest2()
{  
    if (window.ActiveXObject)
    {   
        xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {   
        xmlHttp2 = new XMLHttpRequest();
    }
}

function handleStateChange1() 
{ 
   if(xmlHttp.readyState == 4 && xmlHttp.status == 200 ) 
   {   
       var data;
       data = xmlHttp.responseText;
       document.getElementById('container').innerHTML = data;
   }
}

function senddata(id)
{ 
   createXMLHttpRequest();
   xmlHttp.onreadystatechange = handleStateChange1;
   xmlHttp.open("GET", "http://weblinkchecker.forum-source.tk/crawler.php?link=" + links.replace('&','0123456789abcdef'), true);
   xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   xmlHttp.send("&type=anythinghere&anothervar=datahere");
   document.getElementById(id).innerHTML = "Successful !";
}  

function handleStateChange2() 
{ 
   if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200 ) 
   {   
       var data;
       data = xmlHttp2.responseText;
       document.getElementById('container2').innerHTML = data;
   }
}

function sendForLinks()
{ 
   createXMLHttpRequest2();
   xmlHttp2.onreadystatechange = handleStateChange2;
   xmlHttp2.open("GET", "http://weblinkchecker.forum-source.tk/links.php?link=" + links.replace('&','0123456789abcdef'), true);
   xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   xmlHttp2.send("type=anythinghere&anothervar=datahere");
}

window.onload = function()
{ 
   loaded();
}

</script>

As you can see its a web link checker, there is a bit css that I didn’t upload, also there a lot of php using ajax but none of that is having an affect on the code and I also removed any innerHTML functions. Sorry for having such a large piece of code.

if any one could tell me why html5 local storage is saving last it would be a huge help. I tried echoing out data and it just gives out the old data and not the recent. I feel like I hit a brick wall with this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:53:52+00:00Added an answer on May 18, 2026 at 10:53 am

    First off, your code is quite hard to read, please work on your coding style, for example:

    1. Use more than 1 space for per indent
    2. Don’t place stuff on the same line with opening and closing curly braces
    3. Use spaces around ==, != etc.

    This will make your code a lot more readable 🙂

    But on to your problem:

    // this looks like a callback....
    chrome.tabs.getSelected(null,function(tab) { 
        var temp;
        temp = tab.url;
        localStorage['tab'] = temp;
        console.log(temp);
    });
    
    // this will most likely get executed BEFORE the callback gets called
    // therefore the values just hasn't been changed yet
    links = localStorage['tab'];
    rule = localStorage['ok0'];
    search = links.indexOf(rule);
    

    You most likely need to move the rest of the loaded function into the callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.