Google Answers Logo
View Question
 
Q: Sample Code for cross site XML with site dependent content ( No Answer,   1 Comment )
Question  
Subject: Sample Code for cross site XML with site dependent content
Category: Computers > Internet
Asked by: st225-ga
List Price: $60.00
Posted: 05 Sep 2006 11:36 PDT
Expires: 05 Oct 2006 11:36 PDT
Question ID: 762435
Hi--

I want to let others create a dynamic block on their website that
downloads content from mine. This is something similar to the Amazon
associates process that
will produce customized ads. Can anyone
point me toward some example code that will:

* Provide a Javascript library that can be loaded from any website
with script tags. So

http://bobbyblogger.com/blog.html

will have a script tag like:

<script src="http://mysite.com/mycode.js">

* This library (mycode.js) will create a block, perhaps an iframe, that
sits inside of blog.html and load dynamic content from mysite.com.

When I try to do this with my first approximation, I get security
problems. How can I avoid this? I know that Amazon and others do this
successfully.

Your answer will provide some basic code that shows how it can be done
across domains.

Thanks.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Sample Code for cross site XML with site dependent content
From: golubeff-ga on 10 Sep 2006 14:28 PDT
 
Actually, it is impossible to download any content from one site to
another one within JavaScript. This technology called AJaX, but it
only allows you to download data from only your site.

For example:

You can insert 

<script type="text/javascript" src="http://mydomain.com/script.js"></script> 

on page http://mydomain.com/page.html and it will successfully
download data, but if you insert:

<script type="text/javascript" src="http://mydomain.com/script.js"></script> 

on page http://someotherdomain.com/page.html, it will not work. It
will say "Access denied".

If you want to solve this problem you should not download data from
website in your javascript, but you should print it.

For example, you may have a javascript code like this:

var p = document.body.appendChild(document.createElement('p'))
p.appendChild(document.createTextNode('It works!'));

and it will work, wherever you place it on
http://mydomain.com/page.html or http://anythingelse.com/page.html

But, I guess you want javascript to load dynamic data, don't you?
In this case you should use server side scripts like perl, php or anything else.

For example, if you create a php script http://mydomain.com/script.php like this:

<?
$data = getSomeData();
?>

var p = document.body.appendChild(document.createElement('p'))
p.appendChild(document.createTextNode('<?=$data?>'));

and call it like:

<script type="text/javascript" src="http://mydomain.com/script.php"></script>

wherever from http://mydomain.com/page.html or http://anythingelse.com/page.html,

it will work and reproduce and html code like this:

<p>$data</p>

$data is a PHP variable, containing any text. You can write data from
database or a file in this variable, and javascript will show it.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy