javascript - 如何从 iframe 重定向到另一个 url 并在 iframe 的父级上打开它?

标签 javascript jsp scriptlet

我有一个名为 p1.jsp 的父 jsp。当我单击此 jsp 上的链接时,它会打开一个名为 iframe.jsp 的 iframe。现在 iframe.jsp 中有一个链接,单击该链接时,它必须在关闭 iframe 模态窗口后将用户导航到另一个 url,但该 url 必须在父 session 中打开。这意味着 parent.jsp 将被 new.jsp 的内容替换。

我找出了这样的代码:

<script type="text/javascript">
function closeMyModal()
{
//Closing Iframe modal 
window.parent.parent.document.getElementById('ovr1').style.display = 'none';
window.parent.parent.document.getElementById('cnt1').style.display = 'none';
<%
String hamlistVal = request.getParameter("hamlistVal");
%>
//Open the new.jsp on the p1.jsp i.e. relace p1.jsp with new.jsp
window.location.href="<%=com.pack.href.getCamHref()%>&hamlistVal=<%=hamlistVal%>";

}
</script>   

我的 iframe 模式正在关闭,但它没有导航到 new.jsp。 我在这里做错了什么?请帮忙。

最佳答案

出于安全目的,不允许您的 iFrame 访问父框架。不允许使用导航功能。如果我没记错的话,iFrame 可以读取其父窗口的位置,但不能设置它。

此 JavaScript 函数是在 iFrame 中还是在父窗口中?

关于javascript - 如何从 iframe 重定向到另一个 url 并在 iframe 的父级上打开它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14157427/

相关文章:

javascript - JSP:提交前确认

javascript - 如何在jsp中将javascript变量传递给java scriptlet

javascript - 在javascript中用双引号替换逗号

javascript - 从js UDF输出INT64

jsp - 使用表达式语言设置 session 属性

javascript - 在jquery中,如何获取使用复选框选择的表的特定行的值?

java - 设置 session 变量的 scriptlet 的替代方案?

javascript - 使用bootstrap将数据发送到jsp页面中的模态表单

javascript - 彩盒来帮忙!嵌入 YouTube 视频

javascript - 如何确定数据属性是否设置为空值?