简体   繁体   English

Chrome扩展程序无法创建Cookie

[英]Chrome extension can't create cookie

Firstly, I'm crap at English, I hope you'll understand everything.. 首先,我不太喜欢英语,希望您能理解所有内容。

I have created a small extension on google chrome. 我在Google Chrome上创建了一个小扩展程序。 Basically it does this : 基本上是这样的:

  • When you click on the icon of the extension, it displays a form ( popup.html ) 当您点击扩展程序的图标时,它将显示一个表单(popup.html)
  • When you click on the submi button, it create a new cookie ( popup.js ) 当您单击submi按钮时,它将创建一个新的cookie(popup.js)

popup.html popup.html

    <!doctype html>
    <html>
      <head>
        <title>Getting Started Extension's Popup</title>
        <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"         target="_blank" rel="stylesheet">
        <style>
          body {
          overflow-x: hidden;
          background-color: white;
          width: 170px !important;
          height: 200px;
          }
        </style>
        <script src="popup.js" langage="javascript"> </script>
      </head>
      <body>
        <center>
          <form action="online.html"><input id="alertButton" type="submit" value="submit"></input>
          </form>
        </center>
      </body>
    </html>

popup.js popup.js

    function myAlert()
    {   
        chrome.cookies.set({url : "testing.com", domain : "www.testing.com", name : "name1", value: "value1", path : "/"}) ;
        alert("after");
    }

    document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('alertButton').addEventListener('click', myAlert);
    });

So yeah.... It doesn't create any cookie at all. 是的...。 它根本不会创建任何cookie。 I don't understand, I've been trying to fix this for hours. 我不明白,我已经尝试修复了几个小时。 The alert("after") shows well. 警报(“之后”)显示良好。

I need an assist please, thank you for your help! 我需要帮助,谢谢您的帮助!

Cookie does not work in chrome when you run the file locally. 当您在本地运行文件时,Cookie在chrome中不起作用。

You need to run this file from web server. 您需要从Web服务器运行此文件。

Like you can put this file into htdocs of xampp if you will use xampp, and run this like 就像您可以使用xampp一样,可以将此文件放入xampp的htdocs中,并像这样运行

localhost/popup.html

You can get the Apache (web server) and Mysql (database) into xampp software. 您可以将Apache (Web服务器)和Mysql (数据库)插入xampp软件。

you cant see it since you are running on your local machine ie C://documents...etc . 您看不到它,因为您正在本地计算机上运行,​​即C://documents...etc。 You need a server. 您需要一台服务器。 ie localhost/index.html. 即localhost / index.html。 you can use aptana and create a web project in it. 您可以使用aptana并在其中创建一个Web项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM