是否可以覆盖来自父级的iFrame中的javascript?如果是这样的话? [英] Is it possible to override javascript in an iFrame from the parent? If so how?

查看:187
本文介绍了是否可以覆盖来自父级的iFrame中的javascript?如果是这样的话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的一个触摸屏应用程序中使用Telerik RadSpell控件。我已经成功地设计了它的样式但是这个糟糕的东西使用window.alert和window.confirm来提示用户是否想要保持更改等。

I'm using the Telerik RadSpell control in one of our touchscreen applications. I've managed to style it just right however the darn thing uses window.alert and window.confirm for prompting the user if they want to keep changes etc.

我想要禁用这些警报而不必拆开和修改telerik控件。

I want to disable these alerts without having to pull apart and modify the telerik controls.

问题是拼写检查对话框使用iframe而我似乎无法覆盖窗口iframe中的.confirm功能。

The issue is that the spellcheck dialog uses an iframe and I can't seem to override the window.confirm function inside the iframe.

用于测试覆盖确认的示例代码。

<!-- 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>






结果


Results in

是否可以覆盖来自父母的iframe中的javascript?如果是这样的话?

Is it possible to override the javascript in an iframe from the parent? If so how?

推荐答案

我在第一个论坛中分享了一个更简单的解决方案,它演示了如何覆盖cancelHandler并隐藏确认对话框。

I just shared an easier solution in the first forum, which demonstrates how to override the cancelHandler and hide the confirm dialog.

为方便起见,我将粘贴以下解决方案:

For your convenience I am pasting the solution below:

我建议一种更简单的方法来禁用弹出窗口它是覆盖cancelHandler函数。为此,请按照以下步骤操作:

I would propose an easier way to disable the popup and it is to override the cancelHandler function. To do that follow the steps below:

1)在Web应用程序的根目录中创建一个名为dialog.js的JS文件,并使用以下函数填充它: p>

1) Create a JS file named dialog.js in the root of the web application and populate it with the following function:

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属性以指向此文件,例如

2) Save the file and set the DialogsScriptFile property of RadSpell to point to this file, e.g.


3)测试解决方案。

我希望这会有所帮助。

这篇关于是否可以覆盖来自父级的iFrame中的javascript?如果是这样的话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆