Results 1 to 21 of 21
-
05-08-2005, 09:58 PM #1Junior Guru Wannabe
- Join Date
- Nov 2001
- Location
- U.S.A
- Posts
- 32
Detect If Javascript is Disabled?
Hey,
Well I'm working on my blog. I am trying to stop people from spamming my blog. So I used javascript. But of course you can easily disable javascript to get around it.
So what I would like to do is if javascript is disabled then display an error page saying in order to post javascript must be enabled. So a different url.
Thanks,
Will
PS: I'm new to javascript so be nice.
And yes it is not the only security feature. They must type in a speical code too, that changes on each view. I use javascript to make sure they supply a valid name, email address, and comment. So atm you can still post empty comments if you disable javascript. Maybe there is a better way of doing this?God Bless America
-
05-08-2005, 10:05 PM #2Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
Form validation is best done through server-side scripting (PHP, ASP, CFM, even PERL/CGI works reasonably well). This is because a lot of people will disable JS for good reasons, or it will be disabled on their behalf by the device they're using, the IT department at their corporation, etc.
However, if you're still interested in pursuing JS form validation, try serving up the HTML using a JavaScript include using document.write, and for your error message, place it in <noscript> tags. That'll do the trick nicely.Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
-
05-08-2005, 11:33 PM #3Web Hosting Guru
- Join Date
- Mar 2005
- Posts
- 297
Just have a "test javascript" page.
'If you see this so-and-so javascript is working properly."
If you do not see anythin in the space above, click here. Then have the link lead to how to enable Javascript.
-
05-09-2005, 02:49 PM #4ThirtySx Bits Forever!
- Join Date
- Jul 2001
- Location
- Canada
- Posts
- 1,284
Try this ...
<html><head><title>Javascript Test</title></head>
<body>
<script type="text/javascript">
<!-- // Begin
window.location.href = "./main-page.html";
// End -->
</script>
<noscript>
<h2>This site requires javascript be enabled to view. Please enable javascript in your browser and reload this page. </h2>
</noscript>
</body>
</html>"Obsolesence is just a lack of imagination."
-
05-10-2005, 12:49 AM #5Junior Guru Wannabe
- Join Date
- Nov 2001
- Location
- U.S.A
- Posts
- 32
Hey,
OMG did not relize it was that easy.
Thanks a lot,
Will
Update:
Well not working here. Using php files btw. It just ignores the noscript it seems.
What I really need is an if statement.
So what I want to do is if javascript is enabled then run this code, else if javascript is disabled then run this code instead. Or simply display an error message.
Also, the_pm I do no know php yet but am willing to learn. Do you have maybe an example of this type of thing in php. Tried finding one that I would unstand but no luck. Thanks!Last edited by war59312; 05-10-2005 at 12:59 AM.
God Bless America
-
05-10-2005, 08:42 AM #6Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
Actually, I'm not the right person to ask about form validation through server-side programming. This is the right way to go about things, but that's not my area of expertise
I'm surprised the <noscript> content didn't do what you expected it to do. Did you not see the contents in the <noscript> tags when you disabled JavaScript, and if not, did you see anything different at all?Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
-
05-10-2005, 07:05 PM #7ThirtySx Bits Forever!
- Join Date
- Jul 2001
- Location
- Canada
- Posts
- 1,284
Originally posted by war59312
Hey,
Well not working here. Using php files btw. It just ignores the noscript it seems.
What I really need is an if statement.
So what I want to do is if javascript is enabled then run this code, else if javascript is disabled then run this code instead. Or simply display an error message.
it's a bit of a cludge but this is a simple way to give you one more option ...
<html>
<head>
<title>Javascript Test</title>
<meta http-equiv="refresh" content="15; url=./javscript-not-enabled-page.php" />
</head>
<body>
<script type="text/javascript">
<!-- // Begin
window.location.href = "./javascript-enabled-page.php";
// End -->
</script>
<noscript>
<h2> This site requires javascript be enabled to view. Please enable javascript in your browser and reload this page. If you do not wish to enable javascript, and are not redirected in a few seconds to an alternate page click <a href="javscript-not-enabled-page.php"> HERE </a>. </h2>
</noscript>
</body>
</html>"Obsolesence is just a lack of imagination."
-
05-10-2005, 09:34 PM #8Web Hosting Guru
- Join Date
- Mar 2005
- Posts
- 297
What about a double redirect?
Javascript first - timeout 4 seconds.
PHP second - timeout 12 seconds to a "Javascript isn't enabled" message page.
That way there is no way for them to see the content unless it is working. Make sure to put a "please wait" message of some sort.
-
05-10-2005, 09:52 PM #9ThirtySx Bits Forever!
- Join Date
- Jul 2001
- Location
- Canada
- Posts
- 1,284
The above does just that.
The page loads and starts the <meta> redirect timer and continues to load the rest of the page.
If javascript is enabled then you get immediately redirected to the proper page.
If javascript is not enabled you see the advisory message and when the <meta> times out get directed to an alternate page. In case the timeout doesn't work for some reason they can click the alternate link directly.
The only way to get to the page that requries javascript is if it's enabled, or they view the page source and extract the url manually.
It's not really that complicated and requries no server-side scripting at all."Obsolesence is just a lack of imagination."
-
05-10-2005, 10:25 PM #10Web Hosting Guru
- Join Date
- Mar 2005
- Posts
- 297
Ah ok, I didn't notice the META tag.
-
05-10-2005, 11:33 PM #11Junior Guru Wannabe
- Join Date
- Nov 2001
- Location
- U.S.A
- Posts
- 32
Well for some reason the noscript does not work with wordpress.
Tested in IE 6, FireFox 1.03 and FireFox 1.04 RC nightly build, and Opera 8.0.
Works fine though like above just by itself.
But not in wordspress which is php. Even though I tried adding it in and out of the <?php> code. Should work. Even add <html> tags.
Even added it to html template page and it still does not work.
So I dont know what the deal is.
Well here is my blog so if u want to see what I am trying to get at.
http://wars-realm.com/blog/?p=1#comments
Just try to make an empty comment as a guest to see javascript in action.God Bless America
-
05-11-2005, 08:46 AM #12Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
That's very strange. It's just standard (X)HTML markup. I can't think of a single reason why Wordpress would filter this particular tag out. It shouldn't matter that the page extension is .php, as long as in the end it's outputting (X)HTML markup. BigBison is very familiar with Wordpress. I'll ask him if he's seen this behavior before.
Re: the test/redirect scheme
This is a dangerous type of mechanism to deploy for a couple reasons. First of all, anytime you can avoid making someone wait to reach their content, you've done them a favor. If this all happened in a blink of an eye, that would be one thing. But having to wait even a few seconds every time you enter a site is downright annoying. Some browsers come with meta redirects turned off, and some have redirects optional. So there's that usability perspective. Second, search engines find this type of stuff to be annoying too. The entry page, the top index page, is not the place to monkey around with redirects if it can be helped. Again, maybe it can't be helped, but you want to avoid it at all costs.
Server side validation solves all of these problems. Again, I can't write the code myself, but from what I've seen, it's not too difficult to do. I'd ask about this in the programming forum.Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
-
05-11-2005, 10:05 AM #13rogue element
- Join Date
- Jun 2004
- Location
- Northwest Colorado
- Posts
- 4,636
I think there are plenty of existing plugins for WP which address this problem, instead of making your own solution. For help, the WordPress forums are probably a much better place to look:
http://wordpress.org/support/
Sorry I can't be of any help here.Eric J. Bowman, principal
Bison Systems Corporation coming soon: a new sig!
I'm just a poor, unfrozen caveman Webmaster. Your new 'standards' frighten, and confuse me...
-
05-11-2005, 10:23 AM #14Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
(sorry Eric - for some reason I thought I remembered you having a history with WP, my bad )
Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
-
05-11-2005, 01:44 PM #15rogue element
- Join Date
- Jun 2004
- Location
- Northwest Colorado
- Posts
- 4,636
Well, I have been re-coding WP for my own purposes (to use XSLT templates instead of what's in there already) over the past couple of weeks, as the_pm is aware. But I forgot to mention that I'm a noob with it, in fact I have not yet begun to blog, so I haven't tackled the comment-spam issues yet.
-
05-13-2005, 02:40 AM #16Junior Guru Wannabe
- Join Date
- Nov 2001
- Location
- U.S.A
- Posts
- 32
ok i found a php solution
thanks a lot,
WillGod Bless America
-
09-22-2005, 08:41 PM #17New Member
- Join Date
- Sep 2005
- Posts
- 1
why the need for php to detect?
perhaps instead of worrying to redirect if javascript is turned OFF...why not redirect when it is turned ON instead? no <noscript> tags involved...if javascript is turned on then redirect to javascript page. if not, well simply do what the <noscript> does but in html not script tags. it's simple, but wanted to share with others trying to detect js w/o scripting
bsl
-
09-22-2005, 10:38 PM #18PHP for breakfast
- Join Date
- May 2004
- Location
- Lansing, MI, USA
- Posts
- 1,548
this is actually quite simple...
In your form, have something like...
<input type="submit" id="nojs" value="Submit"><input type="button" id="js" value="Submit" style="display: none;">
Then in your javascript
document.getElementById('nojs').style.display = 'none';
document.getElementById('js').style.display = 'inline';
It just takes some careful planning to make your pages friendly for everyone.Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large
-
09-23-2005, 07:01 AM #19Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
Umm Jacob...if someone does not have JS enabled, those buttons won't work, including the 'nojs' one
Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
-
09-23-2005, 07:08 AM #20PHP for breakfast
- Join Date
- May 2004
- Location
- Lansing, MI, USA
- Posts
- 1,548
Originally posted by the_pm
Umm Jacob...if someone does not have JS enabled, those buttons won't work, including the 'nojs' oneJacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large
-
09-23-2005, 07:21 AM #21Retired Moderator
- Join Date
- May 2004
- Location
- Pflugerville, TX
- Posts
- 11,231
Ah ah. I see what you've done now. The part I missed was that those two DOM statements were part of an onload function.
Sorry - carry onStudio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design