【问题标题】:MathJax not working with iFrameMathJax 不适用于 iFrame
【发布时间】:2015-03-02 03:50:46
【问题描述】:

我试图通过点击事件在 iFrame 上调用 MathJax 函数。这是代码

html

<body onLoad="ifon();">
    <iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;"></iframe>
<button onclick="refresh();"></button>
</body>

javascript

function ifon(){ 
    richTextField.document.designMode = 'On'; 
}
function refresh(){
    var richTextField = document.getElementById("richTextField");
    if(richTextField != null) {
        var get_iframe_text = richTextField.contentWindow.document.body.innerHTML;
        if(get_iframe_text.slice(-6) == "$$<br>"){
            //Trying to call MathJax on iFrame
            MathJax.Hub.Queue(["Typeset",MathJax.Hub,richTextField]);
            alert("Success");
        }
    }
}

仅当最后六个字符为$$&lt;br&gt;时才会执行嵌套if条件的refresh()

谁能帮我在 iFrame 上调用 MathJax.Hub.Queue([]) 吗?

【问题讨论】:

    标签: javascript jquery html iframe mathjax


    【解决方案1】:

    您不能使用 iframe 外部的 MathJax 来处理 iframe 内的数学运算。您需要在 iframe 本身内加载 MathJax。如果需要,您仍然可以通过调用 iframe 内部的 MathJax 从外部触发 MathJax,前提是内容来自与容器相同的域。否则,您需要设置一个事件监听器并使用postMessage 与 iframe 进行通信。

    【讨论】:

    • 感谢您的回复。因为我以前从未使用过 iFrame,所以你能指导我如何在 iFrame 中加载 MathJax。请给我一些演示代码
    【解决方案2】:

    我终于找到了解决这个问题的方法。 只需将 iFrame 替换为 HTML5 ContentEditale Div。

    现在一切正常...

    【讨论】:

      猜你喜欢
      • 2015-08-13
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多