Using Iframes and Cross Domain Scripting
So I didn’t write for a long time, and its about time to do that. I`v few subjects to talk about, but today I will share my thoughts about iframes and cross domain scripting.
Iframe is an old HTML element which lets you load another page inside your current page. People say that iframes are old and useless for us, but I think they wrong.
Why?
Sometimes we want to make things that seems impossible because of our browsers security rules. There are lots of guides and tutorials about cross domain scripting, and seems that some very good implementation in few well known projects:
You may try and view those products source code, and… if you have enough skill, and I`m sure you do, you will notice that they are using lots of ways to bypass cross domain scripting while trying to be as safe as they can.
So the idea is to allow our customers to use our product while they don’t need to understand any programming code.The customers will just have to add a piece of our code to their website and we will be able to control it without any dependency on our customer. Lets just view some examples:
Lets pretend that Facebook and Google are trying to create some kind of chat integration. Facebook finally understood that GTalk is better then Facebook Chat and they want to use GTalk instead.
- Before we start make sure you have some kind of web server on your computer \ remote web server.
- We will have to define our Hosts file and add two domains:
127.0.0.1 www.google1.com
127.0.0.1 www.facebook1.com
If you are using remote web server, don’t forget to change 127.0.0.1 to your server’s DNS.
- now lets create the following directories and files:
/frames/
/frames/google.com.html
/frames/facebook.com.html
/frames/default.com.html
My advice is creating two separate Virtual hosts (Examples: Apache, IIS) so you will feel this implementation as it real.
After creating local\remote environment we can start use some code. lets start from our “Parent” window, which will be Facebook.