javascriptjspscriptlet

How to redirect to another url from iframe and open it on the parent of the iframe?


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 .


Solution

  • 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