Preserving newline characters in data:text URI

前端 未结 2 1811
小蘑菇
小蘑菇 2021-01-14 04:53

I have a button in my extension that triggers the following code:

chrome.tabs.create({url: \'data:text;base64,\'+btoa(data), active:false});
<
2条回答
  •  礼貌的吻别
    2021-01-14 05:21

    My recommended solution is to not use Notepad, because it does not recognize non-Windows line formats. If you still want to be able to use Notepad with your output, replace all line feeds (0x0A) with carriage return+line feed pairs (0x0D 0x0A).

    chrome.tabs.create({
        url: 'data:text;base64,' + btoa(data.replace(/\n/g, '\r\n')),
        active: false
    });
    

提交回复
热议问题