Forum Moderators: open

Message Too Old, No Replies

Problem with window.location.search

         

cameraguy

9:29 am on Jan 4, 2007 (gmt 0)

10+ Year Member



I am struggling with what looks like a simple task... Yet, none of the numerous tutorials helps. Hopefully you can shed some light.

My goal is to embed a flash object via an javascript page like so:


<script type="text/javascript" src="http://...counter.js?account=12345"></script>

The flash counter is being propery displayed, except that I am unable to grab the argument passed in the url (account=12345). I am using "window.location.search", but it's returning nothing at all. So I check what "window.location" returns and I get the url of the sender page and not the destination! In other words "window.location" returns the url that has the embedded object, not the url of the page that is supposed to display the object.

Here is my script:

On "http://...origin.htm":


<script type="text/javascript" src="http://...counter.js?account=12345"></script>

On "counter.js":


mainURL = window.location; /* returns "http://...origin.htm" and not "http://...counter.js?account=12345"

I hope you can help.

Thanks!

whoisgregg

6:55 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The way that most javascripts handle this issue seems to be by declaring a variable before executing the wrapper function in the include or by setting the variable before calling the javascript.

Example #1 - Call Javascript, set variable, call function

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-123456-1";
urchinTracker();
</script>

Example #2 - Set variables, call Javascript

<script type="text/javascript"><!--
google_ad_client = "pub-123456789";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

cameraguy

1:35 pm on Jan 5, 2007 (gmt 0)

10+ Year Member



Thank you. I am going to test your suggestion.

Nevertheless, I have seen many tools being embedded like this:


<!--************CODE GEOCOUNTER************-->
<script type="text/javascript" src="http://geovisit.com:82/private/counter.js?id=123456myblog"></script>
<!--************END CODE GEOCOUNTER************-->

cameraguy

4:00 pm on Jan 5, 2007 (gmt 0)

10+ Year Member



whoisgregg

The second solution works great for me. I find it even simpler since I do not have to extract the variables from the url...

Thanks!