sessionStorage.setItem在firefox /中不起作用,无法将page的id从page1传递到page2

时间:2016-02-09 07:42:51

标签: javascript html firefox

以下代码适用于Chrome,但不适用于Firefox。我想在“关于”页面打开相应的手风琴面板,当它在“主页”页面上点击它的链接时。 [onclick - 主页必须关闭,页面必须打开]

主页:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style type="text/css">
    .bs-example{
        margin: 20px;
    }
a{
margin:20px;
}
</style>
<script type='text/javascript'>//<![CDATA[


function myFunctionId (id) {
sessionStorage.setItem("sent", id); 
window.open("about.html","_self");    


}

//]]> 

</script>


</head>

<body style="padding-top:50px;">
  <a onclick="myFunctionId(this.id);" id="header1">Panel1</a></br>
  <a onclick="myFunctionId(this.id);" id="header2">Panel2</a></br>
  <a onclick="myFunctionId(this.id);" id="header3">Panel3</a></br>


</body>
</html>   

关于页面:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Bootstrap 3 Accordion</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style type="text/css">
    .bs-example{
        margin: 20px;
    }
</style>
<script type='text/javascript'>//<![CDATA[
$(document).ready(function(){
    var a = sessionStorage.getItem("sent");
if (a == "header1") {
    document.getElementById('collapseOne').classList.add('in');
} else if (a == "header2") {
    document.getElementById('collapseTwo').classList.add('in');
} else if (a == "header3") {
     document.getElementById('collapseThree').classList.add('in');
}
else {
    greeting = "Good evening";
}
document.getElementById("demo").innerHTML = greeting;
});
//]]> 

</script>

</head>
<body><p id="demo"></p>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">1. What is HTML?</a>
                </h4>
            </div>
            <div id="collapseOne" class="panel-collapse collapse">
                <div class="panel-body">
                    <p>HTML stands for HyperText Markup Language. HTML is the main markup language for describing the structure of Web pages. <a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">2. What is Bootstrap?</a>
                </h4>
            </div>
            <div id="collapseTwo" class="panel-collapse collapse">
                <div class="panel-body">
                    <p>Bootstrap is a powerful front-end framework for faster and easier web development. It is a collection of CSS and HTML conventions. <a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">3. What is CSS?</a>
                </h4>
            </div>
            <div id="collapseThree" class="panel-collapse collapse header3">
                <div class="panel-body">
                    <p>CSS stands for Cascading Style Sheet. CSS allows you to specify various style properties for a given HTML element such as colors, backgrounds, fonts etc. <a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
    </div>

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

1 个答案:

答案 0 :(得分:0)

发现问题..使用localStorage.setItem / localStorage.getItem而不是使用sessionStorage.setItem / localStorage.setItem