• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Send HREF From Modal To Parent And Close Modal

This is probably a pretty simple question, but I can't figure it out. I've searched here at EE as well as Google and nothing.

I have a modal window which has an href (url). When the user clicks on the href I want to pass that href to the parent window and then close the modal. I've got it working, based on a previous question, where when you click on the href inside the modal, a new window opens. But I don't want that. I just want to pass the href from the modal to the parent window and then close the modal. Is this possible?

Here's what I've got so far:
<a href="http://myHREF.com" onclick="parent.close()">Click here</a>

Open in new window

0
biglarrrr
Asked:
biglarrrr
2 Solutions
 
sunithnairCommented:
Yes sure you can do it this way
Test1.htm (Your parent window)
 
<html>
<title>Test</title>
<head>
<script>
function Go( )
{
      var strReturnValue = "";
      strReturnValue = window.showModalDialog( "test.htm" )
      alert( strReturnValue );
}
</script>
</head>
      <body>
            <input type="button" value="Go" onclick="Go( );">
      </body>
</html>
 
Test.htm (your modal dialog window)
 
<html>
<head>
<title>Modal Dialog</title>
</head>
      <body onunload="window.returnValue = document.getElementById( 'hLink' ).href;">
	    <a href="http://myHREF.com" id="hLink" onclick="window.close()">Click here</a>
      </body>
</html>

Open in new window

0
 
fsze88Commented:
try use onmousedown event on <a> tag instead of onclick...
this is a way it could do your goal and simplest .
master.html
<html>
<title>Test</title>
<head>
<script>
function showModalDialogFun()
{
      var strReturnValue = "";
      strReturnValue = window.showModalDialog( "showModalDialog.html" )
      alert( strReturnValue );
}
</script>
</head>
      <body>
            <input type="button" value="show Modal Dialog" onclick="showModalDialogFun();">
      </body>
</html>
 
 
 
showModalDialog.html
<html>
<head>
<title>Modal Dialog</title>
</head>
      <body >
            <a href="http://www.google.com"  onmousedown="window.returnValue = this.href;window.close()">Click here</a>
      </body>
</html>

Open in new window

0
 
biglarrrrAuthor Commented:
Thanks to the both of you.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now