我在我的web应用程序中使用jquery并使用iframe来显示托管在同一websphere服务器上的应用程序。通过下面的代码,我就能实现自动登录到在iframe显示Web应用程序....Jquery错误 - >权限被拒绝访问属性文件
JSP
<form:form id="posManagerLoginForm"
action="${posManagerUrl}"
target="posManagerFrame"
method="post"
class="ym-form whitenopadding">
<input type="hidden" name="user_name" value="myusername" />
<input type="hidden" name="password" value="mypassword" />
</form:form>
<div class="ym-gbox">
<iframe id="posManagerFrame" name="posManagerFrame" class="posManagerFrame"></iframe>
</div>
JS
$().ready(function() {
$("#posManagerLoginForm").submit();
});
到目前为止好,但现在我现在正在尝试更改JS以便能够在登录发生后,即在表单提交后,获取iframe中的内容。
$().ready(function() {
$("#posManagerLoginForm").submit(function(e){
e.preventDefault();
this.submit();
var iframe = $("#posManagerFrame").contents();
return true;
});
$("#posManagerLoginForm").trigger("submit");
});
正如你所看到的,我注册了一个表单提交函数并尝试并在加载时触发函数。我有两个问题....
- 我得到权限被拒绝试图让iframe的内容时访问属性文件错误。
- 尽管.trigger(“submit”)语句确实会导致我的函数执行,但它似乎会提交表单并触发该函数。我试图不提交表单直到this.submit()语句。
有没有人知道我要去哪里错了?
今天早上我已经发布了几个问题。对于那个很抱歉。谢谢你的帮助。
不要以为你可以获得iFrmae的内容。我过去使用过window.postMessage。有一个规范。 https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage尽管你需要一个回退。 – Leeish
感谢您的输入。由于一些愚蠢的原因,我们不得不在公司支持ie6,所以我不认为这是我的选择。我的终极目标是能够拦截用户点击iframe中的注销按钮的事件,因为注销时浏览器已关闭。因此,作为替代方案,我可能会尝试查看是否可以拦截关闭的浏览器事件,并以某种方式检查请求是否来自iframe。 – Richie
我只是不认为这是可能的,如下所述Alex。这只是一个权限问题。否则,我可以在您的银行网站上嵌入iFrame,并从该iFrame中获取我想要的任何内容。只是不允许,除非你控制两个页面,我认为只有postMessage。你可以围绕一个方向(如果你控制两个页面)将内容从iframe推送到临时文件,从父页面轮询查找临时文件,然后在存在时抓取它。但不完全理想或光滑。 – Leeish