Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13093

Re: How call program and/or conditional display

Date 2012-03-27 10:29 -0800
From Robert Baer <robertbaer@localnet.com>
Newsgroups comp.lang.javascript
Subject Re: How call program and/or conditional display
References <P4ydnWrnbOuL2OzSnZ2dnUVZ_gqdnZ2d@posted.localnet> <jksq3q$la5$1@news.albasani.net>
Message-ID <BtmdnYafb4luZezSnZ2dnUVZ_qqdnZ2d@posted.localnet> (permalink)

Show all headers | View raw


Stefan Weiss wrote:
> On 2012-03-27 07:41, Robert Baer wrote:
>>     OK, in an HTML page via a JS function, i get a user's country code.
>>     How do i either pass that to the HTML code to conditionally run/show
>> results from part of that code, or conditionally run/jump to another
>> HTML page as if one clicked on an href?
>
> First of all, the appropriate place to select and assemble region
> dependent content is on the server side. In the following, I'm assuming
> you're limited to JS for some reason.
>
> To navigate to a new page you can use the "location" object:
>
>     window.location.href = "http://blah/page?cc=" + myCC;
>
> This will trigger a new request, of course. It will also mess with the
> visitors' history when they try to use the back button. That can be
> worked around by using the replace() method:
>
>     window.location.replace("http://blah/page?cc=" + myCC);
>
> Still, not recommended.
>
> If you want show or hide areas of your page depending on the country
> code, you could set their CSS display value:
>
>     document.getElementById("para-india").style.display = "block";
>     document.getElementById("para-europe").style.display = "none";
>
> All of the regional variants have to be present on the page for this to
> work. Visitors without JS will only ever see the initial state, which
> will probably have only one of these blocks visible by default. Visitors
> without CSS support (this includes search engines!) will see and
> potentially index everything.
>
> If you want to load the regional content after the original page has
> loaded, use an XMLHttpRequest. An introduction to Ajax would go too far
> here, but there are many tutorials and examples on the web and in the
> archives of this group. The FAQ has some pointers as well. Use the
> Google cached version if the FAQ is down again.
>
> Again - the cleaner, faster and usually simpler way to do this is not in
> the client, but on the server.
>
>
> - stefan
   Thank you very much; i will play around with these ideas and see how 
well dumb, stupid me does.
   It is impossible for the server (as configured, and i have absolutely 
NO say over that) to do anything WRT client data.
   Google Analytics cannot and will not get any info beyond the fact 
that the first/main page has been accessed (ie: just a dumb counter).
   Things like:
<a href="http://www.oil4lessllc.com/6222350.PDF" 
onClick="that=this;_gaq.push(['_trackEvent,'pdf','download','PatM',that.href]);setTimeout(function() 
{ location.href=that.href }, 200);return false;">Mosley (Titan's HV 
regulator)</a><br>
  just plainly do not work no matter what is done with the code.
  Once in a great while RANDOMLY maybe ONE of the lines like that works, 
but it is very rare.
   Hell, it is so bad that even the 301 permanent redirect does not 
always work! Accessing one way at times gets recorded the other way - 
but results for viewer / browser appears to be the full http:// but 
stupid, dumb i cannot tell.

   Thanks again.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How call program and/or conditional display Robert Baer <robertbaer@localnet.com> - 2012-03-26 21:41 -0800
  Re: How call program and/or conditional display Stefan Weiss <krewecherl@gmail.com> - 2012-03-27 18:32 +0200
    Re: How call program and/or conditional display Robert Baer <robertbaer@localnet.com> - 2012-03-27 10:29 -0800
  Re: How call program and/or conditional display Dr J R Stockton <reply1213@merlyn.demon.co.uk.not.invalid> - 2012-03-28 18:53 +0100
    Re: How call program and/or conditional display Robert Baer <robertbaer@localnet.com> - 2012-03-30 00:56 -0800
      Re: How call program and/or conditional display Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-30 04:05 -0700
        Re: How call program and/or conditional display Bart Van der Donck <bart@nijlen.com> - 2012-04-05 07:15 -0700
          Re: How call program and/or conditional display "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-05 22:56 +0000
            Re: How call program and/or conditional display Bart Van der Donck <bart@nijlen.com> - 2012-04-07 00:32 -0700
              Re: How call program and/or conditional display "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-07 07:51 +0000

csiph-web