是否可以从父级覆盖 iFrame 中的 javascript?如果是这样怎么办?
我在我们的一款触摸屏应用程序中使用 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?如果是这样怎么办?
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.
I want to disable these alerts without having to pull apart and modify the telerik controls.
The issue is that the spellcheck dialog uses an iframe and I can't seem to override the window.confirm function inside the iframe.
Sample Code to test overriding 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>
Results in
Is it possible to override the javascript in an iframe from the parent? If so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚在第一个论坛中分享了一个更简单的解决方案,它演示了如何覆盖cancelHandler并隐藏确认对话框。
为了您的方便,我将解决方案粘贴在下面:
我会提出一种更简单的方法来禁用弹出窗口,它是重写 cancelHandler 函数。为此,请按照以下步骤操作:
1) 在 Web 应用程序的根目录中创建一个名为dialog.js 的 JS 文件,并使用以下函数填充该文件:
2) 保存该文件并将 RadSpell 的 DialogsScriptFile 属性设置为指向该文件,例如
3) 测试解决方案。
我希望这有帮助。
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:
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.
您可以使用 javascript IFF 获取对内部窗口的引用,该框架与父级框架来自相同的域。
You can get a reference to the innerwindow using javascript IFF the frame is from the same exact domain as the parent.
您应该能够:
也许这样的东西可能对您来说效果很好:
这会将 iframe 的确认链接到父级的确认,如果您已经在父级中对确认进行了一些处理,那么这很好。
请注意,您还需要为可能的未定义对象添加一些处理。
You should be able to:
Perhaps something like this might work nicely for you:
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.
您可以查看以下资源,这可能对您的情况有所帮助:
http ://www.telerik.com/community/forums/aspnet-ajax/spell/how-do-i-turn-off-the-confirm-dialog.aspx
和
http://www.telerik.com/help/aspnet -ajax/spell-client-check-finished.html
它们展示了如何删除 RadSpell 确认和警报弹出窗口。
此致,
瘤胃
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