Chrome扩展程序简单弹出窗口不会保留在最后状态

时间:2012-02-01 02:06:07

标签: google-chrome google-chrome-extension popup

现在我确定你们中有些人听说过Byron Nuclear Plant发生的事件(我碰巧住在附近)以及美国和加拿大发生的大规模地震。 ( BTW :我找到了this分机,您可以在全球范围内监控地震)

无论如何,随着所有这些问题的继续,我想更好地观察核电站,我已经知道了Radiation Network所以我做了一个名为Radiation Map的镀铬扩展,由扩散网络驱动(虽然我与辐射网没有任何联系)

我所做的不仅仅是我自己,但每个人都可以监控美国,日本,南美和欧洲的辐射水平。 (我知道我没有做太多工作,但你看到了原因)

然而,我有一个问题,我无法弄清楚。当我打开弹出窗口时,我正在查看日本的辐射水平,当我关闭弹出窗口时,它会回显示美国的辐射水平。我如何做到这一点让它留在用户离开的地方,比如我的案例日本在这个例子中? (我尝试了内容脚本,但是css和jquery没有加载)

清单

{
    "name": "Radiation Map",
    "version": "1.0.1",
    "description": "See what radiation levels are anywhere in the United States, South America, Japan, and Europe! Updated in real time every minute.",

    "browser_action": {
        "default_icon": "images/logo.png",
        "default_title": "Radiation Map",
        "popup": "index.html"
    },

    "icons": {
        "48": "images/48x48.png",
        "128": "images/128x128.png",
        "256": "images/logo.png"
    }
}

弹出

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/rmd.js"></script>
</head>
<body id="radiationmap">
    <div id="rmlbbg"></div>

    <div id="topnavradiation">
        <ul id="menu">
            <div id="themedrop">
                <table>
                    <tr><td>
                        <button id="cus">Contiguous United States</button>
                    </tr></td>
                    <tr><td>
                        <button id="hawaii">Hawaii</button>
                    </tr></td>
                    <tr><td>
                        <button id="alaska">Alaska</button>
                    </tr></td>
                    <tr><td>
                        <button id="sa">South America</button>
                    </tr></td>
                    <tr><td>
                        <button id="japan">Japan</button>
                    </tr></td>
                    <tr><td>
                        <button id="europe">Europe</button>
                    </tr></td>
                </table>
            </div>
            <li><button id="about">About</button></li>
            <li><button id="home">Home</button></li>
            <li><button id="location">Location</button></li>
        </ul>
    </div>

    <div id="radiationmap">
        <div id="cusmap">
            <img src="http://www.radiationnetwork.com/GGFTPMap.jpg" width="752" height="478">
        </div>
        <div id="alaskamap">
            <img src="http://www.radiationnetwork.com/Alaska.JPG" width="752" height="478">
        </div>
        <div id="hawaiimap">
            <img src="http://www.radiationnetwork.com/Hawaii.JPG" width="752" height="478">
        </div>
        <div id="samap">
            <img src="http://www.radiationnetwork.com/Paraguay.JPG" width="752" height="478">
        </div>
        <div id="japanmap">
            <img src="http://www.radiationnetwork.com/Japan.JPG" width="752" height="478">
        </div>
        <div id="europemap">
            <img src="http://www.radiationnetwork.com/Europe.JPG" width="752" height="478">
        </div>

        <table width="752">
            <td><img src="images/LegendWeb.bmp"></td>
            <td><img src="images/Nuclear.bmp"> Nuclear Site</td>
            <td>Alert Level = 100 CPM</td>
        </table>
    </div>

    <div id="aboutradiationmap">
        Radiation Map is powered by the <a href="http://radiationnetwork.com/" target="_blank">Radiation Network</a>, and without them this extension couldn't be possible.

        <p><a href="http://www.youtube.com/mikethedj4" target="_blank">Michael</a> created this extension for obvious reasons, and is in no way affiliated with the Radiation Network.</p>
        <hr>
        <center>Take control over your life, and stay safe!<br />
        <em>Much Love!</em>

        <p><a href="http://swagbucks.com/refer/mikethedj4" target="_blank"><img src="images/swagbucks.jpg"></a></p>

        </center>
    </div>
</body>
</html>

RMD.JS (隐藏效果,并显示监控辐射水平的其他地图)

$(document).ready(function() {
    $('div#alaskamap, div#hawaiimap, div#samap, div#japanmap, div#europemap, div#themedrop, div#aboutradiationmap, div#rmlbbg').hide();

    $('button#home').click(function() {
        $('div#rmlbbg, div#aboutradiationmap').fadeOut(400);
        $('div#themedrop').slideUp(400);
    });

    $('button#about').click(function() {
        $('div#rmlbbg, div#aboutradiationmap').fadeToggle(400);
        $('div#themedrop').slideUp(400);
    });

    $('button#location').click(function() {
        $('div#themedrop').slideToggle(400);
    });

    $('button#cus').click(function() {
        $('div#alaskamap, div#hawaiimap, div#samap, div#japanmap, div#europemap').slideUp(400);
        $('div#cusmap').delay(400).slideDown(400);
    });

    $('button#europe').click(function() {
        $('div#alaskamap, div#hawaiimap, div#samap, div#japanmap, div#cusmap').slideUp(400);
        $('div#europemap').delay(400).slideDown(400);
    });

    $('button#japan').click(function() {
        $('div#alaskamap, div#hawaiimap, div#samap, div#cusmap, div#europemap').slideUp(400);
        $('div#japanmap').delay(400).slideDown(400);
    });

    $('button#sa').click(function() {
        $('div#alaskamap, div#hawaiimap, div#cusmap, div#japanmap, div#europemap').slideUp(400);
        $('div#samap').delay(400).slideDown(400);
    });

    $('button#alaska').click(function() {
        $('div#cusmap, div#hawaiimap, div#samap, div#japanmap, div#europemap').slideUp(400);
        $('div#alaskamap').delay(400).slideDown(400);
    });

    $('button#hawaii').click(function() {
        $('div#alaskamap, div#cusmap, div#samap, div#japanmap, div#europemap').slideUp(400);
        $('div#hawaiimap').delay(400).slideDown(400);
    });

    $('div#rmlbbg').click(function() {
        $('div#rmlbbg, div#aboutradiationmap').fadeOut(400);
    });

});

1 个答案:

答案 0 :(得分:7)

每次弹出窗口都会重新加载页面,这意味着状态不会自动保留。您可以使用sessionStorage来记住当前会话的设置(如果您希望它在浏览器重启后继续存在,则可以使用localStorage)。像这样:

$(document).ready(function() {

    ...

    $('button#cus').click(function() {
        $('div#alaskamap, div#hawaiimap, div#samap, div#japanmap, div#europemap').slideUp(400);
        $('div#cusmap').delay(400).slideDown(400);
        sessionStorage.selectedMap = "cus";
    });

    ...

    // "Click" the button corresponding to the map previously selected
    var selectedMap = sessionStorage.selectedMap || "cus";
    $('button#' + selectedMap).click();
});