Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross Site JavaScript

Status
Not open for further replies.

BomberMan2K

Programmer
Sep 19, 2007
36
IL
Hi guys,
I've seen this javascript being embedded across different sites. Like google does with ti's adwords and google analytics.

I want my javascript code to be embedded in other sites as well, so they can get html code from me to be displayed at their site, according to the parameters they pass to me.

For example - let's say I have a database of names and passwords, and I wish to get the name as a parameter for my JS code, and it will print the password in the site where it was requested from.

Can any please help with this coding approach?

btw, I don't mean to use AJAX here - just plain Javascript.

Thanx.
Roman.
 
That's kind of tricky. It might be possible to use location.search to get the value of the query string sent to the JS file, but I don't know if that would work or not.

Ideally a pure JavaScript implementation should work like this, right?
Code:
<script src="[URL unfurl="true"]http://domain/script.js?user=soandso&action=profile"></script>[/URL]

There might be a way to parse the query string sent directly to the JavaScript file like that, but more likely you'll get the query string of the page that included the JavaScript.

You could do what Google AdSense does and do something along the lines of:
Code:
<script src="[URL unfurl="true"]http://domain/script.js">[/URL]
var user = "soandso";
var action = "profile";
</script>

Otherwise, the only other solution I can think of would be to use PHP or CGI as your JavaScript. i.e.

Code:
#!/usr/bin/perl -w

use CGI;
my $q = new CGI;

my $name = $q->param('name');
my $act  = $q->param('action');

print "Content-Type: text/javascript\n\n";
print qq~
// Your JavaScript Code Here
document.onLoad = myFunction();

function myFunction() {
   window.alert ("name: $name");
   window.alert ("action: $action");
}
~;

And then
Code:
<script src="[URL unfurl="true"]http://domain/script.cgi?name=soandso&action=profile"></script>[/URL]

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top