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

牧云@^-^@ 提交于 2019-12-06 01:40:38

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:

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) 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) Save the file and set the DialogsScriptFile property of RadSpell to point to this file, e.g.

3) Test the solution.

I hope this helps.

You can get a reference to the innerwindow using javascript IFF the frame is from the same exact domain as the parent.

//Get iframe element by getElementById, frames[0], or whatever way you want
var myFrame = document.getElementById("myFrame");
//Get the window of that frame, overwrite the confirm
myFrame.contentWindow.confirm = function(msg){ alert("I overwrote it! : " + msg); }

You should be able to:

document.getElementById('iframe').contentWindow.confirm = [this is confirm in the iframe];

Perhaps something like this might work nicely for you:

document.getElementById('iframe').contentWindow.confirm = window.confirm;

This would link the confirm of the iframe to the confirm of the parent, which is nice if you already have some handling for confirms in the parent.

Note that you also will want to add some handling for possible undefined objects.

var iframe = document.getElementById('iframe');
//iframe exists
if(iframe){
 var iframe_window = document.getElementById('iframe').contentWindow;
 //window exists (won't if frame hasn't loaded)
 if(iframe_window){
  iframe_window.confirm = window.confirm;
 }
}

You can take a look at the following resources, which could be helpful for your scenario: http://www.telerik.com/community/forums/aspnet-ajax/spell/how-do-i-turn-off-the-confirm-dialog.aspx and http://www.telerik.com/help/aspnet-ajax/spell-client-check-finished.html

They show how to remove the RadSpell confirm and alert popups.

Best regards, Rumen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!