使用javascript在另一个网页的console.log中获取一个页面本地存储值?

使用javascript在另一个网页的console.log中获取一个页面本地存储值?,javascript,html,local-storage,Javascript,Html,Local Storage,我有一个网页,其中包含一个范围滑块,每个滑块位置在滑动时都有一个值。该值将发生变化,该值存储在furniture.html的本地存储中。现在,我希望本地存储中的该值作为form.html网页中的html表单字段值获取 我的JS代码: window.addEventListener('load', function() { var imagePath = "../static/images/"; var localStorageSliderNumber; var loca

我有一个网页,其中包含一个范围滑块,每个滑块位置在滑动时都有一个值。该值将发生变化,该值存储在furniture.html的本地存储中。现在,我希望本地存储中的该值作为form.html网页中的html表单字段值获取 我的JS代码:

window.addEventListener('load', function() {

    var imagePath = "../static/images/";
    var localStorageSliderNumber;
    var localStorageImagePath; 
    if (window.localStorage.getItem('sliderValue') != null) {
        localStorageSliderNumber = window.localStorage.getItem('sliderValue');
    } else {
        window.localStorage.setItem('sliderValue', '1');
        localStorageSliderNumber = 1;
      }
    if (window.localStorage.getItem('imagePath') != null) {
        imagePath = imagePath + window.localStorage.getItem('imagePath') + ".jpg";
    }

    var rangeslider = document.getElementById("sliderRange");
    var output = document.getElementById("sliderOutput");
    var images = document.getElementById("sliderImages");
    rangeslider.addEventListener('input', function() {
      for (var i = 0; i < output.children.length; i++) {
        output.children[i].style.display = 'none';
        images.children[i].style.display = 'none';
      }
      i = Number(this.value) - 1;
      output.children[i].style.display = 'block';
      images.children[i].style.display = 'block';

      window.localStorage.setItem('imagepath', rangeslider.getAttribute('value'));
      window.localStorage.setItem('sliderValue', (i+1));
      function isValue(){  
        var storedValue = JSON.parse(localStorage.getItem("sliderValue"))
        $("#furniture").val(storedValue);
      }
    });


  });
window.addEventListener('load',function(){
var imagePath=“../static/images/”;
var localStorageSliderNumber;
var-localStorageImagePath;
if(window.localStorage.getItem('sliderValue')!=null){
localStorageSliderNumber=window.localStorage.getItem('sliderValue');
}否则{
window.localStorage.setItem('sliderValue','1');
localStorageSliderNumber=1;
}
if(window.localStorage.getItem('imagePath')!=null){
imagePath=imagePath+window.localStorage.getItem('imagePath')+“.jpg”;
}
var rangeslider=document.getElementById(“sliderRange”);
var output=document.getElementById(“sliderOutput”);
var images=document.getElementById(“幻灯片图像”);
rangeslider.addEventListener('input',function(){
for(var i=0;i
furniture.html代码为:

<div class="image mt-3 mb-3" id="sliderImages">
          <img src="../static/images/1.jpg" width="400" height="180">
          <img src="../static/images/2.jpg" width="400" height="180">
          <img src="../static/images/3.jpg" width="400" height="180">
        </div><br>
        <div class="rangeslider">
          <input type="range" min="1" max="3" value="1" class="myslider" id="sliderRange">
          <div class="container">
          <div id="sliderOutput">
            <div class="col-4">

              <h6 class="display-6 mt-3"><b><center>Starting From Scratch</center></b></h6>
              <p class="demo"><center>I'm designing the room </p>
            </div>
            <div class="col-4">
              <h6 class="display-6 mt-3"><b>Somewhere in Between</b></h6>
              <p class="demo">I'm designing around a few pieces I already own</p>
            </div>
            <div class="col-4">
              <h6 class="display-6 mt-3"><b>Mostly Furnished</b></h6>
              <p class="demo">I want to put the finishing touches on my room</p>
            </div>
          </div>
        </p>
<form >
   <div class="form-group">
     <label for="username">Username</label>
     <input type="text" name="username" class="form-control" required>
   </div>
   <div class="form-group">
      <input type="hidden" name="room" id="name" value=" ">
   </div>
   <div class="form-group" >
      <input type="hidden" name="goal" id="goal" value=" ">
   </div>
   <div class="form-group" >
      <input type="hidden" name="style" id="style" value=" ">
   </div>
   <div class="form-group" >
      <input type="number" name="furniture" id="furniture" value=" ">
   </div>
   <div class="form-group">
      <label for="email">Email</label>
      <input type="text" name="email" class="form-control" required>
   </div>
   <div class="form-group">
      <label for="password2">Password</label>
      <input type="password" name="password" class="form-control" required>
   </div>
   <input type="submit" value="Register" style="background-color:#000080;" class="btn btn- 
   secondary btn-block">
</form>


从头开始

我正在设计房间

介于两者之间

我正在设计一些我已经拥有的作品

大部分家具

我想对我的房间进行最后的润色

我的form.html代码是:

<div class="image mt-3 mb-3" id="sliderImages">
          <img src="../static/images/1.jpg" width="400" height="180">
          <img src="../static/images/2.jpg" width="400" height="180">
          <img src="../static/images/3.jpg" width="400" height="180">
        </div><br>
        <div class="rangeslider">
          <input type="range" min="1" max="3" value="1" class="myslider" id="sliderRange">
          <div class="container">
          <div id="sliderOutput">
            <div class="col-4">

              <h6 class="display-6 mt-3"><b><center>Starting From Scratch</center></b></h6>
              <p class="demo"><center>I'm designing the room </p>
            </div>
            <div class="col-4">
              <h6 class="display-6 mt-3"><b>Somewhere in Between</b></h6>
              <p class="demo">I'm designing around a few pieces I already own</p>
            </div>
            <div class="col-4">
              <h6 class="display-6 mt-3"><b>Mostly Furnished</b></h6>
              <p class="demo">I want to put the finishing touches on my room</p>
            </div>
          </div>
        </p>
<form >
   <div class="form-group">
     <label for="username">Username</label>
     <input type="text" name="username" class="form-control" required>
   </div>
   <div class="form-group">
      <input type="hidden" name="room" id="name" value=" ">
   </div>
   <div class="form-group" >
      <input type="hidden" name="goal" id="goal" value=" ">
   </div>
   <div class="form-group" >
      <input type="hidden" name="style" id="style" value=" ">
   </div>
   <div class="form-group" >
      <input type="number" name="furniture" id="furniture" value=" ">
   </div>
   <div class="form-group">
      <label for="email">Email</label>
      <input type="text" name="email" class="form-control" required>
   </div>
   <div class="form-group">
      <label for="password2">Password</label>
      <input type="password" name="password" class="form-control" required>
   </div>
   <input type="submit" value="Register" style="background-color:#000080;" class="btn btn- 
   secondary btn-block">
</form>

用户名
电子邮件
密码
通过此js代码,我将slidervalue获取到furniture.html网页中的本地存储,但没有加载到html表单中。我的代码有任何错误:无法读取null的属性'addEventListener'
主要问题是我应该将本地存储中的slidervalue获取到另一个html页面form.html

如果这两个页面都是网站/应用程序的一部分,那么本地存储将是相同的。要查看存储的数据,请点击F12->应用程序选项卡->本地存储。如果它是一个单独的网站/应用程序,则不可能从一个网站访问另一个网站的本地存储。是的,在本地存储中,它在那里,但我希望它在另一个网页@sameer的控制台中打印,并且这些网页都是相同的applicationfurniture。js:21 Uncaught TypeError:无法读取null的属性“addEventListener”window.onload我收到这个错误,你能创建一个JSFIDLE吗,因为我在你的js代码中找不到
window.onload