2

I have a page I want to use as an extension for chrome. It consists of:

-INDEX.HTML:

<html>
<body>
    <div id="one">
        some things
    </div>
    <div id="two">
        some other things
    </div>
</body>

<script type="text/javascript">
    toggle();
    window.onresize = function() {
        toggle();
    }

    function toggle() {
        if (window.innerWidth < 700) {
            document.getElementById('one').style.display = 'none';
            document.getElementById('two').style.display = 'block';
        }
        else {
            document.getElementById('two').style.display = 'none';
            document.getElementById('one').style.display = 'block';

        }
    }
</script>

-AND MANIFEST.JSON:

{
"name": "New Tab Page",
"description": "Woohoo! Description!",
"version": "1.0.0",
"manifest_version": 2,
"icons": {
"128": "icon.png"
},
"chrome_url_overrides": {
"newtab": "index.html"
}
}

When I open index.html with chrome as a local file, it works just fine, and the text changes when the page is resized. When I open the containing folder in chrome://extensions , enter developer mode, and load it as an unpackaged extension, both #one and #two appear, not just #one.

Is there any way I can fix this?

Forge
  • 5,854
  • 6
  • 41
  • 58
jbwar22
  • 186
  • 1
  • 12
  • 2
    Don't use inline js, move the script into a separate file and link it in ` – wOxxOm Oct 14 '15 at 23:09
  • @wOxxOm Great! it worked! I also had some other javascript to run functions in my code, and i created a second javascript file to manage them. when i click on an input button that should run the function, it doesn't. The error is: <<<<>>>> help? I would recommend making a response. – jbwar22 Oct 15 '15 at 00:30
  • 1
    I don't want to make an answer because there are many duplicate questions for that error, the new one too: [onClick within Chrome Extension not working](http://stackoverflow.com/q/13591983) – wOxxOm Oct 15 '15 at 00:47
  • 2
    possible duplicate of [onClick within Chrome Extension not working](http://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) – Zig Mandel Oct 15 '15 at 02:40

0 Answers0