have a small javscript that users can include into their sites like so:
<script src="http://www.mydomain.com/stuff.js?id=99" type="text/javascript"></script>
once included, this adds a clickable link to their page, all works good so far.
now for the part I am stuck on, in stuff.js we need to be able to use the value of id (99 in this case) in the functions
example:
destination = escape('http://mydomain.com/index.php?refferal=ID-VALUE-HERE');
basically just need to replace ID_VALUE_HERE with 99
Any ideas or tips how this relatively simple task could be accomplished?
-
edit or write your own stuff.jsvol7ron– vol7ron2012年05月16日 23:59:53 +00:00Commented May 16, 2012 at 23:59
-
I assume your being "funny"... the question is how to go about making such an edit? how to I access the value of ID? with only javascript, I obviously cannot rewrite the stuff.js file for every user.Mark– Mark2012年05月17日 00:04:31 +00:00Commented May 17, 2012 at 0:04
2 Answers 2
1: Change your server config to interpret .js files as php files.
2: add to your .js file:
var id = "<?php echo !empty($_REQUEST['id']) ? $_REQUEST['id'] : '' ?>";
If you aren't able to rebind the file handling, you can also fix it using .htaccess and mod rewrite.
3 Comments
You can iterate over all script elements in the document, search for the one that loaded your script and extract any parameters from its attributes.
Yet, it would be much better to use (some small and really simple) server side processing to echo the url arguments directly into the delivered source code. Don't forget to escape them properly.