[Javascript] Javascript detection
Paul Novitski
paul at juniperwebcraft.com
Tue Jan 2 15:31:39 CST 2007
At 1/2/2007 11:35 AM, tedd wrote:
>Now, how to get around not downloading a test page before presenting
>the "final" product I don't think is possible for one has to use js
>to see if it's there, or not, before passing that condition back to
>the server, right?
>
>If you have a different method, I would love to hear it.
Hi Tedd,
There's such a discontinuity between the server and the client that I
think the best you can hope for is a probability, not a surety, that
a particular condition exists on the client side. You can make
assumptions when you download a page to the client that might cease
to be true by the time the page renders or at any time during the
user's interaction with the page, and you can make assumptions on the
basis of what you get back from the client that might no longer be
true by the time you download the next page.
I think the problem you're ultimately trying to solve is faux. The
server CAN'T know whether or not javascript "is running" because the
server-side script completes its execution before the page finishes
rendering and the user interacts with it client-side. It's like
deciding whether to leave your great-great-grandchild an inheritance
of a comb based on whether they've got long hair. The expression of
the problem infers a simultaneity that just isn't there. Even if you
could look ahead in time and see that the child has hair and how long
it is, by the time that child is born and reaches the age of
inheritance they may have decide to cut their hair or they might be
undergoing medication that causes them to lose it entirely. Better
to leave an inheritance that they can use regardless.
So I believe a more robust approach to web design is to deliver pages
that work whether or not javascript is running. If the user can
interact with the page controls as enhanced by javascript, then
disable javascript, then continue interacting with the page
successfully, I would slap that page with a big fat gold star. In
that model the server doesn't attempt to determine whether or not
javascript is running, it downloads pages that can accommodate both scenarios.
Back to your problem, though: For reasons I don't know you've
rejected suggestions of using POST and GET and cookies which are the
primary mechanisms we've been given to share information between
client & server. I wouldn't want to discourage you from cutting a
new path -- go for it, maybe you'll figure out something that no one
else has seen -- but I would think it would be somewhat more
efficient to find a means that does use the familiar methods.
For example, here's one using GET:
<a
href="switchboard.php?something=123456&dest=contact.php">Contact Us</a>
That is, pass a value to PHP which it can store any way you want
between page-views, then redirect to the desired page. This link
will work whether or not javascript is running, although if js is
enabled it could modify the querystring to enhance the process.
Here's one using POST:
<form action="contact.php">
<input type="hidden" value="123456" name="something" />
<input type="submit" value="Contact Us" />
</form>
or:
<form action="switchboard.php">
<input type="hidden" name="something" value="123456" />
<input type="hidden" name="destination" value="contact.php" />
<input type="submit" value="Contact Us" />
</form>
Here again, javascript can create, modify, and delete hidden form
fields at any time until submit, and can take control of the submit
method to work its magic at the last instant.
As long as you're using a double hit on the server to accomplish your
goal, I would imagine these solutions could fit inside your
parameters (as I guess them to be).
Regards,
Paul
More information about the Javascript
mailing list