我正在尝试通过单击事件调用 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");
}
}
}
refresh() 嵌套 if 条件仅当最后六个字符为 $$<br>
时才会执行
谁能帮我如何在 iFrame 上调用 MathJax.Hub.Queue([]) ?
最佳答案
您不能从 iframe 外部使用 MathJax 来处理 iframe 内的数学。您需要在 iframe 本身内加载 MathJax。如果需要,您仍然可以通过调用 iframe 内部的 MathJax 从外部触发 MathJax,前提是内容来自与容器相同的域。否则,您需要设置一个事件监听器并使用 postMessage
与 iframe 进行通信。
关于javascript - MathJax 无法与 iFrame 配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28802440/