JavaScript Popup"行动是不安全的"

时间:2014-07-14 12:52:03

标签: javascript json

我正在JavaScript中创建一个名为List Maker的Web应用程序,其中一个功能是能够从JSON导出/导入数据。对于导出和导入JSON数据,将显示一个弹出窗口,允许用户复制/输入数据。

但是,我无法显示弹出窗口,因为我一直收到此错误:

[Exception... "The operation is insecure."  code: "18" nsresult: "0x80530012 (SecurityError)"  location: "<unknown>"]

这是显示弹出窗口的函数:

function JLShowExportDialog()
{
    var w = window.open('', '', 'width=400,height=400,scrollbars');

    w.document.write(document.getElementById("exporttojson").innerHTML);
    w.document.body.style.fontFamily = "sans-serif";
    w.document.getElementById("jsontext").innerHTML = GetJSONFromList();
    w.document.title = "Export List To JSON";
    w.document.close();
}

exporttojson div:

<div id="exporttojson" style="display: none">
    <h1>Export to JSON</h1>
    <p>The text in the box below contains the JSON.</p>
    <textarea id="jsontext">
    </textarea>
</div>

GetJSONFromList()函数的代码:

function GetJSONFromList()
{
    return JSON.stringify(LMList);
}

1 个答案:

答案 0 :(得分:0)

它应该是这样吗?

function GetJSONFromList(LMList)
{
    return JSON.stringify(LMList);
}