Welcome to WebmasterWorld Guest from 54.163.40.152

Forum Moderators: open

Message Too Old, No Replies

Modal Window Redirect

     

intcon

2:23 am on Feb 28, 2012 (gmt 0)

5+ Year Member



Hello all..

I have a modal window that I'd like to make clickable - ie, the user clicks anywhere in the window and it takes them to the website....not just closes the window, but takes them to another website (the new one!) Even if they click the close button, it needs to redirect to the new. (I didn't invent this idea, I'm just trying to do what they asked!)
Here's the test page..
[monarchcottages.com...]

I tried to make the page clickable -
onClick="document.location.href='http://www.google.com';"
in the body tag, then in the table tag, but no go.

Is there anything that can close the modal window AND redirect to the new site?

thanks in advance

carrie

daveVk

5:46 am on Feb 28, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



For starters try

in main page add function to do the work

function doWork() {
// code to close popup ?
document.location.href='http://www.google.com';
}

in popup

onclick="window.opener.doWork();"

intcon

2:40 pm on Feb 28, 2012 (gmt 0)

5+ Year Member



ok...tried that ..i added in
<script type="text/javascript">
function doWork() {
// code to close popup ?
document.location.href='http://www.google.com';
}
</script>

to the head in the main document and
<body onclick="window.opener.doWork();">

to the modal window.

but it didn't work. Even added the link to the graphics but then it just loads the google.com website into the modal window frame itself, doesn't break out of the modal window at all...

help? =)

rocknbil

4:57 pm on Feb 28, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Keep banging around at it, you've got the right tools and will get it. :-)

- Base window has code to open new (modal?) window.
- New window opens. From that window set main window's location: window.opener.document.location
- from the popup window, close (window.close() will close CURRENT window.)

Don't use inline event handlers, esp. on body (go ahead to get it working, but it's not needed.) Use something the users will understand and recognize:

<a id="the-link" href="some-meaningful-url.html">Go</a>

<script type="text/javascript">
window.onload=function() {
document.getElementById('the-link').onclick=function() { return doSomething(); };
};

function doSomething() {
alert('do something');
return false;
}

</script>

Or a form:

<form action="some-meaningful-action.php" id="the-form">
<input type="submit" value="go">
</form>

window.onload=function() {
document.getElementById('the-form').onsubmit=function() { return doSomething(); };
};

daveVk

12:40 am on Feb 29, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



but it didn't work


Make sure you have error reporting turned on, you should to least get an error indication.

Try alert in doWork ?

Note that security restrictions apply ( same origin policy ) if frame content from different domain than main page.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month