In my project,
I have created a code snippet which can be copied and then put in any website. It shows my content on other websites.
What I am using now is :
<script type='text/javascript'>
var user = 'abc';
var age = '23';
document.write('<iframe src="http://www.mysite.com/page.php?user='+ user + '&age=' + age + '" ></iframe');
</script>
In page.php,
I do some processing based on user and age and show dynamic content.
My approach works fine.
But when I look into some good standard ways to do such tasks, I find a different way.
Take an example of google adsense code.
<script type='text/javascript'>
var a = 'somedata';
var b = 'someotherdata';
</script>
<script type='text/javascript' src='http://www.google.com/adsenseurl.js'></script>
I guess, since a and b are global; adsenseurl.js must be using it and may be finally they are showing it on iframe.
So, now the question.
What’s the advantage in using google’s approach and whats wrong in my approach ?
p.s. I know I should try to avoid using iframes but I dont see any other way to accomplish this.
The main difference between your approach and adSense is in my opinion that your code has to be placed where the ads have to appear and loading a script like adsense, they can place the iframe in the DOM after examining the page – using
and/or manipulating the zindex to float the iframe above the page
Lastly the iFrame is useful (regardless of “oh noes – iframes are evil” you may hear) since you can use any css and jquery you like. If the page you are on already has styled divs and old versions of jQuery you will have a lot more work to make it look like you want.