首页 > 解决方案 > Chrome 扩展换行符 (\n) 在 popup.html 中不起作用

问题描述

我的 popup.js 接收一个数组,替换,\npopup.html 页面并将元素打印到该页面。出于某种原因,没有形成换行符,相反,我看到的只是,过去的小空间。

popup.html

    <!DOCTYPE html>
<html>
    <head>
        <link href="popup.css" rel="stylesheet" type="text/css">
    </head>
<body>    
    <h3>Header issues</h3>
    <p class="hdrs">Fetching headers..</p>

    <script src="popup.js"></script>
</body>
</html>

popup.js:

function fixArrayLines(response) {
  var sorted = response.toString().replace(/,/g,',\n');
  return sorted;
}
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  chrome.tabs.sendMessage(tabs[0].id, {type: "getHDR"}, function(response) {
    var sortedRsp = fixArrayLines(response);
    document.querySelector("p.hdrs").textContent = sortedRsp;//if response null, replaces with empty
  });

收到的数组(名为“响应”):

var response =[aba,baba,gaga]

popup.html 页面中出现意外结果

aba baba gaga

我有一个关于最小弹出窗口大小的小 CSS 指令 - 仅此而已,并且清单设置正确。为什么会这样?如何逐行正确地对数组成员进行排序?(以这种方式或任何其他方式)?

标签: google-chrome-extension

解决方案


推荐阅读