Question

I have a parent jsp called p1.jsp . When i click on a link on this jsp , it opens up an iframe called iframe.jsp. Now there is a link in iframe.jsp, which when clicked it must navigate the user to another url after closing the iframe modal window, but that url must be opened on the parent session. This means the parent.jsp will be replaced by the contents of the new.jsp.

I fished out a code like this :

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

My iframe modal is getting closed , but it is not navigating to the new.jsp . What am i doing wrong here ? Kindly help .

Was it helpful?

Solution 2

Ok i got the solution to this .

I just needed to provide my full url inside the href of my iframe.jsp as :

<a href = "<%=com.pack.href.getCamHref()%>&hamlistVal=<%=hamlistVal%>"/>

Then i needed to set the attribute target as "_parent" like this :

<a href = "<%=com.pack.href.getCamHref()%>&hamlistVal=<%=hamlistVal%>" target="_parent"/>

This makes the iframe disappear and opens the new.jsp on the p1.jsp.

Hope this helps others.

I got this one when i referred this thread : Stack Thread

OTHER TIPS

For security purposes your iFrame will not be allowed access to the parent frame. No navigation functions are allowed. If I'm not mistaken the iFrame can read the location of its parent window but cannot set this.

Is this JavaScript function in the iFrame or the Parent Window?

There is also another way to achieve this. My solution is better when you redirect to a specific page from multiple sources.

In my case I just want to make sure that this page (which is my login page) would not open in the iframe. You can also add more condition if you want to do this from defined urls.

<script>
    if(window.self !== window.top)
        window.top.location.href = "<%=request.getContextPath()%>";
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top