Forum Moderators: open

Message Too Old, No Replies

problem with redirecting to another domain

         

voice10

5:35 pm on Apr 9, 2006 (gmt 0)



Hi all, I've some sponsored URLs in my page shown inside an <iframe>. When the user clicks on one of those URLs I track the click at the server side and my server returns an alternate URL(sponsor url) with 302 status code. But the page gets loaded inside the <iframe> instead of replacing the whole page. In order to avoid I tried to return another page (with return code 200)and execute the following javascript on 'onload'
<code>
function redirect(){
redirect_url = document.getElementById('url_id').innerHTML;
window.location = redirect_url;
top.location.target="_top"
if(window.location.target!= "_top")
top.location.href=window.location.href;
}
</code>
It works but there are two issues with this implementation. 1. the User always sees this intermediate page 2. Back button does not work (need to click twice fast to come back to original page). So what's the best way to redirect to another domain from an iframe?

Thanks a lot in advance.
/SD

kaled

6:17 pm on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By specifying a link target, you may avoid javascript.
<a href="page.html" target=_top>

Alternatively, to avoid breaking the back button, use location.replace(url).

Kaled.