How to pass unknown URL value from browser adress to javascript source url?
The setting: Up until now I have been able to successfully pass a couple
of known GET variables through my javascript src, such that the client
javascript tag will work on any web page, from any domain, like so:
<script id="gbScript" type="text/javascript"
src="http://www.mydomain.com/myremoteapp/scripts/gb.js?clientid=50&domain=someclientdomain.com"></script>
But, now I have need to add one more variable to the source url, and I
need to get it from the url that's in the client's browser.
For example, I need to grab the value of "p" from this web page address:
http://www.yourwebsite.com/?p=2
...and then add it to the url variable string in my client script, like so:
<script id="gbScript" type="text/javascript"
src="http://www.mydomain.com/myremoteapp/scripts/gb.js?clientid=50&domain=someclientdomain.com&p=2"></script>
LIMITATIONS: I can't use server-side code. That's because I have no idea
whether the client will add this script to their php page, aspx page, or
plain old html page.
WHAT I HAVE TRIED: I tried two back-to-back scripts, the first to create a
variable, and then tried to pass that variable in the second script:
<script type="text/javascript">var url = escape(window.location);</script>
<script id="gbScript" type="text/javascript"
src="http://www.mydomain.com/myremoteapp/scripts/gb.js?clientid=50&domain=someclientdomain.com&p="+url+></script>
Unfortunately, the src part of the script tag does not seem to honor or
recognize a javascript variable. Also, on the remote or hosted page that
the script uses, which is php, it does not see the client's url at all,
much less the url variables of the client address.
No comments:
Post a Comment