0

I'm quite new to this. I need to change the popup.html that gets shown in my chrome extension. I have two popup.htmls. I also need to save the value of the users choice.

My options.html:

<html>
<head>
  <script src="options.js"></script>
</head>
<body>
 <label class="paylabel" for="cardtype">Theme:</label>
 <select id="cardtype" name="cards">
 <option value="selectcard">--- Please select ---</option>
 <option value="op1">first</option>
 <option value="op2">second</option>
 </select>

<input type="button" onclick="fun()" value="click here">
 </body>
 </html>

options.js:

   function fun()
  {
   var ddl = document.getElementById("cardtype");
   var selectedValue = ddl.options[ddl.selectedIndex].value;
   if (selectedValue == "op2")
  {
 chrome.browserAction.setPopup({
         popup: 'popup2.html'
     });
   }
  }

My manifest.json:

{
"manifest_version": 2,

"name": "extension name",
"options_page": "options.html",
 ...
 }

This question is not a duplicate, because in my question I'm trying to figure out how to display different popup.htmls according to the users choice. The other question is trying to identify why the onclick function doesn't work within the chrome extension.

KidCoder
  • 333
  • 5
  • 15
  • what exactly is required? is your html is not loaded on plugin? Any change in manifest & html require re-installation of plugin to chrome – Rohit Batta Nov 19 '15 at 10:46
  • no, I have two popup.htmls. I want the user to be able to choose between the two. – KidCoder Nov 19 '15 at 10:48
  • if i could understood you correctly, then you want a configuration for user to choose, which view they want. then you could add a input field on a common html, which will then redirect to either popup based on preference. – Rohit Batta Nov 19 '15 at 10:54
  • 1
    That could work. This is what I originally wanted: I wanted the user to go to the options choose the popup, which would set the popup.html (https://developer.chrome.com/extensions/browserAction#method-setPopup) – KidCoder Nov 19 '15 at 11:01
  • Cool.. You could try this then, enjoy your day.. :) – Rohit Batta Nov 19 '15 at 11:05
  • Umm.. I did try that, but that's the problem it's not working. Check out my code. Thanks, you too :) – KidCoder Nov 19 '15 at 11:06
  • This link could help you understanding the logic to use setPopup method. [Check example here](http://stackoverflow.com/questions/10071357/using-chrome-browseraction-setpopup-per-tab) – Rohit Batta Nov 19 '15 at 11:08
  • @Ahan, inline javascript doesn't work inside chrome extension's pages like options.html – wOxxOm Nov 19 '15 at 11:17
  • @wOxxOm yeah, I thought it wouldn't can you please tell me what to do then? I hope you understand what I'm trying to achieve? – KidCoder Nov 19 '15 at 11:44
  • Sorry @wOxxOm, that's not what I meant. My code is still not working. It's not changing to popup2.html – KidCoder Nov 19 '15 at 11:54
  • @wOxxOm I've added it. – KidCoder Nov 19 '15 at 12:16
  • @wOxxOm Sorry, I'm not sure what I'm doing wrong. If you know the answer, can you post it? – KidCoder Nov 19 '15 at 12:37
  • `fun()` in your html is an inline javascript. You may easily google it, for example: [this](http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/) – wOxxOm Nov 19 '15 at 12:51
  • Thanks @wOxxOm, I figured it out! – KidCoder Nov 19 '15 at 13:02
  • Possible duplicate of [onClick within Chrome Extension not working](http://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) – rsanchez Nov 19 '15 at 14:23
  • @wOxxOm I had also asked how I could save it, I've asked the question here, do you know how to do this please? http://stackoverflow.com/questions/33806467/local-storage-is-being-erased-in-chrome-extension – KidCoder Nov 19 '15 at 15:05

0 Answers0