Mar 27, 2012 5:41 am
Robert BaerOK, 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?
Mar 27, 2012 4:32 pm
Stefan WeissOn 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?
> 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
Mar 27, 2012 6:29 pm
Robert BaerStefan Weiss wrote:
> On 2012-03-27 07:41, Robert Baer wrote:
> 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 >> 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?
>>> 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
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.
Mar 28, 2012 5:53 pm
Dr J R StocktonIn comp.lang.javascript message <P4ydnWrnbOuL2OzSnZ2dnUVZ_gqdnZ2d@posted
.localnet>, Mon, 26 Mar 2012 21:41:50, Robert Baer
<robertbaer@localnet.com> posted:
> 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?
> 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?
A country code set in a computer does not necessarily indicate the
current preferences of the current user.
If alternatives are provided, the user should be enabled to change
preferences at any time, without loss of entered data.
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Previous Thread: Preventing "Prevent this page from creating additional dialogs"
Next Thread: Safari XHR Error
Related Forum Topics
- Baffled trying to call style.display value
- Display inline vs display block pls help
- Conditional statement with an assignment expression
- Photoshop Javascript Conditional not working
- Conditional String.replace regex
- How to programmatically display a value
- How to programmatically display a value
- How can I make the browser display changes at once?
- Display XML content in HTML page
- Strange Delay in Page display (OT ??)