我在我们的一个触摸屏应用程序中使用 Telerik RadSpell 控件。我设法将它的样式设置得恰到好处,但是该死的东西使用 window.alert 和 window.confirm 来提示用户是否要保留更改等。
我想禁用这些警报,而不必拆开和修改 telerik 控件。
问题是拼写检查对话框使用了 iframe,我似乎无法覆盖 iframe 中的 window.confirm 函数。
用于测试覆盖确认的示例代码。
<!-- mainpage.htm -->
<html>
<head>
<script type="text/javascript">
window.confirm = function(msg){ alert(msg); }
confirm("Main Page Confirm");
</script>
</head>
<body>
<iframe src="./iframepage.htm" >
</iframe>
</body>
</html>
<!-- iframepage.htm -->
<html>
<head>
<script type="text/javascript">
confirm("iframe confirm");
</script>
</head>
<body>
Some content.
</body>
</html>
结果在
是否可以覆盖来自父级的 iframe 中的 javascript?如果是怎么办?
最佳答案
我刚刚在第一个论坛分享了一个更简单的解决方案,它演示了如何覆盖 cancelHandler 并隐藏确认对话框。
为了您的方便,我将解决方案粘贴在下面:
我会提出一种更简单的方法来禁用弹出窗口,它是重写 cancelHandler 函数。为此,请按照以下步骤操作:
1) 在 Web 应用程序的根目录中创建一个名为 dialog.js 的 JS 文件,并使用以下函数填充它:
Telerik.Web.UI.Spell.SpellDialog.prototype.cancelHandler = function (e) {
if (this._cancel.disabled) {
return $telerik.cancelRawEvent(e);
}
//changes will be applied only if spell handler response is received, text has changed
//and the user confirms
this.closeDialog(this._spellProcessor && this._spellProcessor.textChanged() && true);
return $telerik.cancelRawEvent(e);
}
2) 保存文件并设置 RadSpell 的 DialogsScriptFile 属性指向这个文件,例如
3) 测试解决方案。
希望对您有所帮助。
关于javascript - 是否可以从父级覆盖 iFrame 中的 javascript?如果是这样怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8929996/