Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript从一个HTML页面获取输入并输出到另一个HTML页面_Javascript_Html - Fatal编程技术网

使用JavaScript从一个HTML页面获取输入并输出到另一个HTML页面

使用JavaScript从一个HTML页面获取输入并输出到另一个HTML页面,javascript,html,Javascript,Html,我有一个HTML页面,上面有一个按钮“保存salt和相关选项卡”,它将当前选项卡的url和salt保存到两个变量中,然后将这些值附加到另一个HTML页面上的表中。但是,关联的JavaScript文件无法从最后一个HTML页面读取要将变量附加到的表。有什么办法吗? 第一个HTML: <html> <h1>Set the number of characters</h1> <input id="num" type = &quo

我有一个HTML页面,上面有一个按钮“保存salt和相关选项卡”,它将当前选项卡的url和salt保存到两个变量中,然后将这些值附加到另一个HTML页面上的表中。但是,关联的JavaScript文件无法从最后一个HTML页面读取要将变量附加到的表。有什么办法吗? 第一个HTML:


<html>
<h1>Set the number of characters</h1>
    <input id="num"  type = "number" value = "20" name = "value"><br><br>
    
    
<div class="spec_symb"><label><input  id = "spec_symb" name=unit  type=radio value=special>Special symbols</label></div>
<div class="alphanumeric"><label><input checked id = "alpanumeric" name=unit type=radio value=alpahnumeric>Alphanumeric symbols only</label></div>
<br>
<button id="click">Generate</button><br>
    <p id="text" ></p>
    
    
<button id="save">Save the salt with the associated tab opened</button>
<p id="string" ></p>
<p id="url" ></p>
<ul>
  
        <li><a href=navigation.html>Back to the Navigation Menu</a></li>
       
      </ul>

    
    
    <script src="salt_genj.js"></script>
    
    
   
    </html>


设置字符数


特殊符号 仅限字母数字符号
生成

在打开相关选项卡的情况下保存盐

JavaScript代码(salt_gen.js):

函数saltgen(长度){
var radio=document.getElementById(“spec_symb”);
var salt=“”;
if(document.getElementById('spec_symb')。选中==true){
var symbols=symbols=“abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyz012456789!@$%^&*()”
else{var symbols=“abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzo123456789”}
var SLENGHT=符号长度;
对于(变量i=0;i
表的最后一个HTML页面

<!DOCTYPE html>
<html lang="en">
<table id="MyTable" class="table table-striped" style="width:100%">
        <tr>
          <th>Webstite</th>
          <th>Salt</th> 
          
        </tr>
        
      </table>
      
      <script src="salt_genj.js"></script>
      
    
</html>

韦氏体
盐

您说过要将其用作Chrome扩展。浏览器扩展有一个background.js脚本,它在扩展运行时运行,可以在多个页面之间连接


您也可以使用cookies或存储API。

选择将它们传递到url查询字符串或存储传递到另一个HTML页面?你有CORS权限吗?@StackSlave我不知道CORS是什么,但我的代码是用来作为Chrome的extension@charlietfl我通过
localStorage.setItem(“vOneLocalStorage”,url)尝试了本地存储;setItem(“vTwoLocalStorage”,salt)var urla=localStorage.getItem(“vOneLocalStorage”);var salta=localStorage.getItem(“vTwoLocalStorage”)
但是变量原来是empyDo你的意思是我应该把JavaScript代码放在background.js中吗?在浏览器扩展中有一个东西叫做消息传递。您可以在扩展的不同脚本之间发送消息。这样做的原因是不同的脚本具有不同的权限。例如,content.js脚本可以编辑与之匹配的网页,而background.js脚本则不能。但是,后台脚本会一直运行,并且可以与不同的选项卡进行通信。您可以使用消息将数据从内容脚本发送到后台脚本。当你转到另一个页面时,你可以要求后台脚本返回消息。据我所知,你建议将变量从salt_gen.js传递到background.js,然后使用background.js填充表格。如何将变量从一个js脚本传递到另一个js脚本?Google的API文档很难导航。我建议阅读Firefox版本。几乎一样
<!DOCTYPE html>
<html lang="en">
<table id="MyTable" class="table table-striped" style="width:100%">
        <tr>
          <th>Webstite</th>
          <th>Salt</th> 
          
        </tr>
        
      </table>
      
      <script src="salt_genj.js"></script>
      
    
</html>