Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show a pop up only once in chrome extension?
    primarykey
    data
    text
    <p>Hi I need to show a pop up in chrome extension. I have set my website as a chrome extension. Here is the use case:</p> <ol> <li>When the user installs the extension, and clicks on the extension icon, it should show a pop up asking his username. </li> <li>When user enters his name and login, the pop up gets closed. </li> <li>This name is stored in <code>local storage</code>. </li> <li>When user clicks the extension icon next time, it checks whether his name is stored in <code>localstorage</code> If not then it should again show pop up otherwise it should navigate to my website.</li> </ol> <p>Now what my problem is that</p> <ol> <li>When I click twice on the icon only, only then pop up appears.</li> <li>After I enter name and click login pop up gets closed which is fine</li> <li>When I click again on icon, actually it should navigate to the website, but in my code it again shows pop up.</li> <li>When I reload the extension, it works correctly.</li> </ol> <p>Please help me. Here is my background.js</p> <pre><code>chrome.browserAction.onClicked.addListener(function(tab) { if(!localStorage.username){ chrome.browserAction.setPopup({ popup: "userinfo.html" }); } else{ //navigate to website }); </code></pre> <p>here is my userinfo.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="test.js"&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;font face="sans-serif"&gt;&lt;b&gt;Enter your Email ID&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt; &lt;form id="userinfo"&gt; &lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;font face="sans-serif"&gt;&lt;label for="user"&gt;Email&lt;/label&gt;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;: &lt;/td&gt; &lt;td&gt;&lt;input type="text" id="user" /&gt;&lt;/td&gt;&lt;span id="semail"&gt;&lt;/span&gt; &lt;/table&gt;&lt;br&gt;&lt;br&gt; &lt;font face="sans-serif"&gt;&lt;input type="submit" id="login" value="Log In"/&gt;&lt;/font&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>here is my test.js</p> <pre><code> window.addEventListener('DOMContentLoaded', function() { var user = document.querySelector('input#user'); var form = document.querySelector('form#userinfo'); form.addEventListener('submit', function(evt) { evt.preventDefault(); var userStr = user.value; chrome.runtime.getBackgroundPage(function(bgPage) { bgPage.login(userStr/*,pwdStr*/); }); window.close(); }); }); </code></pre> <p>anyone please please help me</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload