Show my website's content on other websites. Is iframe only option?

Posted by Jashwant on Stack Overflow See other posts from Stack Overflow or by Jashwant
Published on 2012-04-05T16:49:42Z Indexed on 2012/04/06 5:29 UTC
Read the original article Hit count: 135

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery