JavaScript Forum

How call program and/or conditional display

Mar 27, 2012 5:41 am
Robert Baer

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?

Mar 27, 2012 4:32 pm
Stefan Weiss
Re: How call program and/or conditional display

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


Mar 27, 2012 6:29 pm
Robert Baer
Re: How call program and/or conditional display

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.




Mar 28, 2012 5:53 pm
Dr J R Stockton
Re: How call program and/or conditional display

In 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?

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.


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
I am creating a table of contents with nested UL lists. Many of the LI tags contain A tags and the UL of a lower-level list. The A tags call a function meant to show toggle display of the lower level lists.
The link passes the "this" keyword to the function, which gets the parent node and then...
Display inline vs display block pls help
http://jsfiddle.net/s6hBG/15/
when i use the display inline for the above menu its not coming properly
i want the horizontal alignment
how to fix the issue
i tried but its not properly aligned with in black bacground
given below is my code

#menu...
Conditional statement with an assignment expression
Before few weeks ago Garret Smith payed attention for "Conditional
statement with an assignment expression":
<URL:http://groups.google.bg/group/comp.lang.javascript/msg/
9299befb874eb9a0>

He maintain theory for readable of code in statements like this one:

var x;
if (x =...
Photoshop Javascript Conditional not working
Any users out there use Javascript for Scripting Photoshop? My
conditional is not working.

Thanks in Advance!



#target photoshop
app.bringToFront();


function fitImage(newImgSize,res) {
var doc = app.activeDocument;
if (res == undefined) res = undefined;
if...
Conditional String.replace regex
I have a block of text, and I'm wanting to do something like, "if THIS
is not preceded by THAT, then replace THAT with THIS + THAT.

Meaning, I have this text:

<DIV style=float:left><FONT color=#ffff80 size=-1 face="Arial,
Verdana, Helvetica, sans-serif"><P><B>


If it's NOT preceded...
How to programmatically display a value
I calculate and want to display the numerical result.

I can do it by assigning to the value attribute of an <input type=text>
element.

However, I don't want the user to be able to change the value displayed.

I tried readonly="readonly" but, unless I had a bug in the code, I found...
How to programmatically display a value
I calculate and want to display the numerical result.

I can do it by assigning to the value attribute of an <input type=text>
element.

However, I don't want the user to be able to change the value displayed.

I tried readonly="readonly" but, unless I had a bug in the code, I found I...
How can I make the browser display changes at once?
When making my test page to measure speeds of PRNGs, I met an
unexpected problem: neither Firefox nor Chrome displayed the changes
to the document before the end of the tests. (Firefox also became
*very* unresponsive.) Opera, on the other hand, behaved as expected -
the changes I made to the...
Display XML content in HTML page
Hi,

I am newbie , I have application in which check-box tree is present. I want to pre-populate the check-box's if user before checked some of those check box.

For that am getting XML format from my back-end perl script as shown below.like , in below XML only 0, 43,44,45,46 and 50 are...
Strange Delay in Page display (OT ??)
Hi:

I have noted a delay of from 5 to 11 seconds in displaying a page sent
from my server to a client (just *me* for now).

I have a very simple page with the following line:

<body onload="setupflds();">

etc,etc
</body>

and the following...