Firefox doesn't allow accessing the parent frame url whereas Chrome allows in case of cross domain

As you know that codeinspections is now malliks and also as you can see any user opening codeinspection gets automatically redirected to malliks.mazic.in, I am making this posting to explain the technical details about how we did that.
Basically in malliks we have created an index page which has an header and iframe which has the source as the codeinspections.blogspot.com and this works as expected. But I wanted to go a step ahead and let anyone coming to codeinspections automatically get redirected to malliks. I did that by adding a javascript code to the blog and the code looks like below:
<script type="text/javascript">
<!--
var urlname=window.location.href;
var flag=0;
try
{
var parenturl=window.parent.location.href;
}
catch(err)
{
flag=1;
}
if(flag==0)
window.location="http://malliks.mazic.in/?url="+urlname;
</script>
This code works in firefox and IE, because these browsers doesn't all you to access the parent frame url if both the parent and child are in different domain. In the above code if user come to site as codeinspections flag will be zero and hence gets redirected to malliks, and when the user is on malliks, javascript code tries to access parent url and gets an exception, therby flag is set to one and hence user is not redirected. I tested this on IE and firefox and it worked fine.
But one of blog reader reported that blog was not opening in the chrome browser and even I tried in browser and it didn't work, it was infinitely getting redirected to malliks, i,e a frame inside a frame and so on infinite frames gets opened. This is because chrome was not giving any exception and it was allowing to freely access the parent frame url. I then added code below to make it work on chrome.
<script type="text/javascript">
<!--
var urlname=window.location.href
var flag=0;
try
{
var parenturl=window.parent.location.href;
var subparent=parenturl.substring(0,22);
if(subparent=="http://codeinspections")
flag=0;
else
flag=1;
}
catch(err)
{
flag=1;
}
//alert(flag+" "+parenturl);

//alert(flag+" "+subparent);

if(flag==0)
window.location="http://malliks.mazic.in/?url="+urlname;
//-->
</script>
With increasing number of browsers(IE6,IE7,firfox 2,firfox 3,chrome IE8), it challenge for developers to write a code which works perfectly on all these browsers. Whats your take on this?

Also Read: Codeinspections Will Now Be Malliks
Google More Confident: Strips off Beta Tag Within 100 Days of Release
Secuirty Issues in Chrome Browser

No comments:

Post a Comment