Get Parent URL With Javascript


I frequently have to create child window and the child windows sometimes need its parent URL, in javascript just create a variable to store the url. In this example I copy the content of parentURL variable to a hidden form element named sourceURL

<script type="text/javascript">
function frmSubmit(){
    parentURL = opener.location.href;
    document.getElementById('sourceURL').value = opener.location.href;
    document.forms['myform'].submit();
}
</script>
<form name="myform" id="myform" method="post" action="target.php">
<input type="hidden" name="sourceURL" id="sourceURL" />
<input type="button" value=" submit " onclick="frmSubmit()" />
</form>