I'm thinking this might be a quick and easy way to lower the form spam on our site just a little bit. The idea being that (I have read) spammers aren't running with javascript enabled. (Or at least they are accessing your website without running javascript. I.e., they aren't browsing up to it in IE or FF.
I can use .asp or .aspx.
The simplest way is to set a cookie via javascript and check for it on postback.However, if you're looking to minimize spam you should actually have the browser perform a simple task which requires javascript execution. See Phil Haack's "Invisibile Captcha Validator" control, which has since been included in his Subkismet library: http://haacked.com/archive/2006/09/26/Lightweight_Invisible_CAPTCHA_Validator_Control.aspx
In .net, you can use Request.Browser.JavaScript to detect if the browser supports JavaScript. However, the user may still have Javascript disabled. An ugly way to check to see if Javascript is enabled, is to use window.location to redirect to page.aspx?jscript=true, and then check Request.Querystring for that value.
So, you want to force users to use JavaScript in order to use your site? I'd rather just use a simple Captcha. If you aren't a big-name site, you can get away with some relatively simple Captchas.
That's how we reduced spam at our site.
To be honest, you shouldn't need to use a server-side language to detect javascript, and furthermore spammers are not necessarily not running javascript. (sorry about the double-negative) Your objective is good, but your approach is wrong - implementing a CAPTCHA, as suggested by a few of our peers, would be a great way to handle this.
I see you've accepted the noscript answer, but how will you use this to fight spam? noscript will allow you to add special content for users without JS, but unless you're generating the rest of your site in JS, it will still be available to user agents without JS.
A captcha of some sort is still likely the best bet. Ultimately, you're trying to get the user agent to prove that it's being controlled by a human, so do your best to make it prove that actual fact, instead of something else. Screen readers for the visually impaired typically go without Javascript, too, and many people browsing from mobile devices have Javascript disabled to speed things up.
Related
Is there any possibility to set the Internet Explorer settings by running Javascript file..?
I want to set the following settings in IE through javascript/Jquery
Go to, ‘Tools’ -> ’Internet options’.
Under ‘General’ tab, click the ‘Settings’ button in the ‘Browsing History’ section.
Choose the radio button "Every time I visit the webpage".
Click ‘OK’ and restart the IE.
This is not possible - it'd be a bit of a security hole if sites were able to do this...
Firstly, the short answer is no: You can't do what you're asking for.
Javascript within the browser is heavily restricted to only being able to access resources for the actual page being viewed. This is an important security feature.
You cannot access other pages or other tabs. You cannot access parts of the browser UI outside of the page itself. You cannot run external programs.
Even if you could, the way you've described it wouldn't work anyway: The settings page you've described is specific to one particular version of IE. So your hypothetical program wouldn't work in any other browser or even any other version of IE.
However, more importantly, you need to ask yourself why you're asking for this.
The thing is that you're trying to solve a problem with your site. You've found something that resolves it, and you've asked a question about how to automate that. But you need to work backward a bit -- stop trying to work out how to automate this particular solution: you need to ask yourself whether there might be a different way of solving the original problem, which could be automated.
The fact is this: the config setting you're trying to change is for handling how the browser deals with caching of files. There are ways of changing the behaviour of caching that can be scripted by your site. You might want to look at questions like this one for example.
The lesson here is this: Don't simply ask how to do something; explain why you're trying to do it as well. There might be an alternative solution that's better than the one you've thought of.
No, it's not possible to do using JavaScript.
This is not what Javascript designed to do. There is only a way to read browser setting from JS - using signed scripts.
It just seems like something that would be really useful when developing server-side code. If you know that the browser won't be using javascript from the server-side, you could easily accommodate the user. Or if you just felt like it, redirect them to a page that says 'hey... we need you to use javascript for our application' etc.
Does anyone know why this is?
See the <noscript> tag, here.
I know it's probably not ideal (I don't have enough experience with it to pick it apart) but it certainly gives us enough flexibility to degrade somewhat gracefully.
As handy as it would be to have your server be aware of your browser's Javascript capability before page rendering began, I can see a strange edge case such as:
// hide malicious code from people without javascript
if ($header['javascript'] == 'false') {
show_regular_safe_website();
} else {
use_some_nasty_javascript_exploit();
}
One way I use is to have a landing page/login page. When the user presses the logon button then use javascript to submit the results or update a hidden field before posting the logon. If javascript is disabled then the javascript will not work and therefore you can assume they have it turned off.
The real reason is that when Netscape came out with JavaScript, they never thought to make the information available in the HTTP headers. Instead they created the <noscript> tag.
I suppose the Accept field could be used to such a purpose, like "Accept: text/javascript". But since it's proprietary the IETF would never include it in any standards and widespread adaptation is therefore unlikely. Web-developers has coped so far.
I've developed a ajax enabled site. However, the site does not currently work without javascript. The site works well on any browser that I've tested as well as iPhone/Nokia phones.
However, should I still worry about javascript support?
I know there are techniques that would get my site to work both with or without javascript, but the refactoring would require some time.
Edit: This application is targeted for our customers that will be using the the system to fill in and handle forms. Professional use mostly.
Javascript is Huge now and since facebook and other large JS Based site, browsers have pushed out new innovations to deal with the latest web changes when it comes to JS
Because of this JavaScript is widely supported and you should not worry dramatically but it still needs to be delt with.
A Simple <noscript> tag to display a message to a user telling them they need javascript to continue
<noscript>
Please enable javascript to use this site
</noscript>
Keep checking your analytics software such as google, mint etc to see what your visitors are using.
That will help you decide how much you have to worry about it
A way to Track non JavaScript enabled browsers is like so
<noscript><img src="noscript.php" /></noscript>
This will load a php file as an image!
the php file
<?php
//Track the user details here inside your database or whatever so you can then see.
//Here send back a 1x1 pixal so the DOM IS ok and to reduce load
$pxl= imagecreate( 1, 1);
header( "Content-type: image/png" );
imagepng( $pxl);
imagedestroy( $pxl);
?>
You could display a message to users with javascript disabled saying that the site will not work properly:
<noscript>
Hey, it seems you have Javascript disabled. Get out of my lawn!
</noscript>
If this is a big deal or not depends on your target audience.
You should always try to keep in mind that a certain percentage of endusers disables javascript in their browser. On the other hand most modern sites don't work anymore or don't always degrade gracefully. It's up to you to either convince your users to enable javascript or to create at least a page with minimal functionality which can be run without javascript.
Grz, Kris.
Most browser today have javascript enabled. One thing to keep in mind is that crawlers/spiders from for example google do not have javascript on.
This depends entirely on your users.
If you can make sure your users browser supports JavaScript, then it's up to you to ensure the actual code is valid and complies to JavaScript standards.
Many argue that pages has be readable by blind people and have all kinds of fallback options, but this depends on your users, and what you require of them.
If you really have to support all kind of phones, and weird devices, just create a separate front-end.
AFAIK, Google bot does not support JavaScript. So, if you want your site to be indexed by search engines, make content accessible without JavaScript.
It depends.
If you're expecting good chunk of traffic from the mobile web-browsers then yes, you must refactor the website to make sure it works well with those client. If majority of the traffic is coming from rich desktop web browsers then, it shouldn't be problem.
Just some short Q regarding javascript and websites.
1- By javascript enabled, does it mean to have 'sun java' installed and enabled in the browser settings? Or does every browser have javascript enabled always?
2- If javascript is disabled, my website for example wouldn't work at all, so what does major developers do in these situations, if the only way to achieve their goal is to use javascript?
3- Is ajax also disabled if javascript is disabled? Also, same for Jquery because its a javascript library ?
Thanks guys
Sun's Java is not the same thing as JavaScript. Java is an extension to the browser which user might or not have installed. JavaScript comes with browser and can be disabled by the user.
Display a notice to the user that he/she should turn JavaScript on.
Ajax and jQuery are Javascript, so yes, they're disabled also.
Question 1: Java and JavaScript are two different languages. JavaScript is a dynamically typed language where Java is strictly typed language (i.e. you have to define variables as int, string, etc...). Every browser except for screen readers should have JavaScript turned on by default. The thing to remember is that users have the ability to turn off JavaScript if they so choose. The reason they turn it off is because during the 90s JavaScript was used in the wrong ways such as creating pop-up after pop-up windows and other mischievous things.
Question 2: You should always develop your website to work without JavaScript turned on. JavaScript is like icing on the cake. It is the fancy behavior that your website has. The technique of developing your website to work with JavaScript turned off but be more "enhanced" when it is turned on is called "Unobtrusive JavaScript". Basically, it means that your users can get to your web pages content without the need of JavaScript. Search in Google for "Unobtrusive JavaScript" and you will find a plethora of information and techniques.
Here are just a couple links to get you started:
A List Apart Behavioral Separation
Easy as Pie - Unobtrusive JavaScript
Question 3: Yes. If JavaScript is turned off then your Ajax methods and jQuery library will not work.
Do some research regarding this topic. You will find a lot of information that will help you in your journey of discovering Unobtrusive JavaScript.
Users can enable or disable javascript in their browser settings. It isn't a matter of what is installed in the browser, but rather the user's preferences.
When you can't use javascript, you generally can accomplish the same thing by doing more postbacks. The user experience will definitely be slower.
Ajax and jQuery rely on javascript being enabled by the user.
No. Javascript and Java are two different thing
Which is why your developers must consider the case where Javascript is disabled. Your site should run gracefully ( albelt with reduce functionality) even if Javascript is not enabled ( such as when on mobile). This means that your should have a basic version of the site for the user without Javascript to browse.
Yes.
All modern browsers come with a built-in JavaScript engine but the user can disable it. JavaScript has a similar syntax as Java (from Sun) but it's a language of its own.
If your website needs JS, then add an HTML element which says "Please enable JavaScript" and make it invisible in one of your scripts. When the users can see it, then she has JS disabled.
AJAX doesn't work when JS is disabled. The same is true for jQuery.
1 - No, javascript is read through web browsers, and is by default on most of the time. A user would normally need to disable it themselves.
2 - There is a development practice called Graceful Degredation which may help you to create websites that will still work if javascript is disabled.
3 - Ajax is much more difficult without javascript, but again Graceful Degredation may help you here.
No. 'sun java' and JavaScript are two different things. JavaScript is present and enabled by default in all modern browsers.
You can place message asking user to enable JavaScript in his browser inside <noscript></noscript> tag.
Yes AJAX and jQuery require JavaScript to be enabled.
Graceful degredation for point 2 is definitely the way to go - jQuery is big on this. Your page contains the markup required for your site to function via postbacks.
This can then be 'hijaxed' by your script to enable AJAX updates etc. This means that if a user is prepared to enable a nicer experience they can.
If you are programming internal intranet sites, you can usually assume that scripting would be enabled - these sites are often very script intensive...
1- Every browse live alone... and so doesnt matter if java is installed for command javascript.
3- AJAX core is javascript. If javascript is disabled, ajax is disabled.
I'm currently building a project and I would like to make use of some simple javascript - I know some people have it disabled to prevent XSS and other things. Should I...
a) Use the simple javascript, those users with it disabled are missing out
b) Don't use the simple javascript, users with it enabled have to click a little more
c) Code both javascript-enabled and javascript-disabled functionality
I'm not really sure as the web is always changing, what do you recommend?
Degrade gracefully - make sure the site works without JavaScript, then add bells and whistles for those with JavaScript enabled.
Everyone else has committed good comments, but there are a few other considerations to make.
Sometimes the javascript will be hosted on a different domain, and be prone to timeout.
Sometimes that domain may become inacessible, while your site remains accessible. Its not good to have your site completely stack itself in this scenario.
For this reason, "blocking" scripts ( ie: document write inline ) like that present in google's tracker, should be avoided, or at very least, should go as late in the page as possible so the page renders whether or not the domain is timing out requests or not.
If you happen to be serving JS from a broken/malicious server, by intent or by accident, one can halt page rendering simply by having a script that serves that javascript which just calls "sleep(forever)" once its sent all the headers.
Some People Use NoScript
Like the above problem, sometimes the clients environment may block certain script sources, be it the users choosing, or other reasons ( ie: browser security satisfactions, odd antivirus/anti-malware apps ). The most popular and controllable instance of this is NoScript, and I myself paranoidly block some of the popular tracking/advertising services with it ( some proxy servers will do this too ).
However, if a site is not well designed, the failing of one script to load still executes code that was dependant on that script being present, which yeilds errors and stops everything working.
My recommendation is :
Use Firebug
Use NoScript and block out everything --> See Site still works
Enable core site scripts that you cant' do without for anything --> See site still works and firebug doesn't whine.
Enable 3rd party stuff --> See site still works and firebug doesn't whine.
There are a lot of other complications that can crop up, but satisfying the above 2 should solve most of them. Just assume that, for whatever reason, one or more resources that comprise a page are viable to spontaneously disappear ( they do, all the time ), and you want the page to "survive" this problem as amicably as possible. For the problems that may persist for < 10 seconds, its not so bad, refresh the page and its fixed, but if its a problem that can occur, and severley hamper usability for an hour or more at a time.
In essence, instead of thinking "oh, theres the edge case users that don't have javascript", try thinking more a long the lines of "its really easy to have something go wrong, and have ALL of our users with broken javascript. Ouch! Lets try make it so we dont' really hose ourself when that does happen"
( I've seen IE updates get rolled out and hose javascript for that entire browser until the people whom wrote the scripts find a workaround. Losing all your IE customers is not a good thing )
:set sarcasm
:set ignoreSpelling
:set iq=76
Don't worry, its only a 5% Niché Market
Nobody cares about targeting Niché markets right? All those funny propeller heads running lynx in their geeky stupid linoox cpus, spending all their time on the intarwebs surfing because they have nothing better to do with their life or money? the crazy security paranoid nerds disabling javascript left and right because they don't like it?
Nobody wants them as your primary customer now do they?
Niché markets. Pfft. Who cares!
:set nosarcasm
Consider your audience
"Degrade gracefully" is generally the best answer. But lots of sites now depend on JS - especially AJAX.
Consider your audience. If your site is aimed at extremely tech-savvy people, the chances of them not having javascript are small, and you can notify them to turn it on if necessary.
If your audience may access your site with mobile devices, don't assume they have JavaScript, and don't even assume they support CSS properly. Aim to degrade gracefully all the way down to bare HTML.
I've learned a lot from my question: What's With Those Do-Not-Use Javascript People
Go with Ajax and Web 2.0. It's the way the web is going and it's wonderful. Isn't Stackoverflow great to be on? It's not quite as nice with your Javascript turned off.
Once you have your site ready, but before you let it go live, test it with Javascript off, and just add whatever you feel you need to make your site appear and function to them. You only need to add what you feel is essential.
Remember, except for visually impared people using screen readers, the others have chosen to turn javascript off. They can also choose to trust your site and turn javascript on for your site if they want to use all the functionality you have. It really is their choice.
As other have said, it should "degrade gracefully".
In other works, it must work without Javascript (period). It doesn't have to work well. The folks who've disabled Javascript know the limitations that causes and have accepted them. But if you are trying to sell them something, it's important that they can still buy it.
On the site I'm designing, there's a javascript-based fly-out menu. With Javascript off, all the flyouts are always open. It doesn't look as cool as it would with JS, but it can still be used to navigate the site.
It depends on how much time you have to develop and maintain both solutions, and how much the non-javascript users are worth to you.
My e-commerce site relies heavily on javascript, and in over a year and a half, I've not received a single complaint.
In fact, I don't think I've seen a single visitor with javascript disabled in any of logs since I started.
That doesn't mean they're not out there. It just means that either (a) they're a tiny percentage, (b) they're not interested in what I'm selling, or (c) both of the above.
Code your web site with support for the bare minimum kind of browser. Then more people can use your site without frustration even if they don't have all the bells and whistles--like Flash, Javascript, and Java--enabled. It may not be practical to continue support for ancient browsers, say Netscape Navigator 4, because a user can be reasonably expected to keep their computer up-to-date. However, features like Javascript, Flash, and Java can be security holes in old or modern browsers, as well as being an annoyance.
Neither of my parents keep Javascript or Flash enabled because they've had too many experiences with them slowing down their already slow connection, crashing their browsers, or being more of an annoyance on sites that use it stupidly (which is a lot of them...) than a useful feature. It's just bad design if, for example, your form requires an AJAX call be made and you can't actually hit a submit button to send the form when Javascript is disabled.
My mother was recently quite frustrated to discover that she is now unable to click through eBay results pages because each one requires Javascript. The only way she can see the next page of results is to turn on Javascript or to show more results per page. Now what reason would there be for page links to require Javascript while the 'results per page' links are just plain links? They should all be plain old HTML links. Maybe Javascript could be used to add some whiz-bang to the navigation, but a user should not be punished with a bad interface for having Javascript disabled. It's stupid on eBay's part, and it causes undue hassle for their users.
I am one of those that uses 'No-Script.' And I can tell you that sites that use javascript and don't work without it enabled is extremely annoying, stackOverflow... No we don't expect it to be very fancy, if I upvote load a new page that says "Thank you."
We expect to be able to use the site with reasonable limitations, don't ever display a page that says JS must be enabled, though, even if the site is crap without it. And yes if your site convinces us to stay we will enable. A function that isn't in common use on the site can also require javascript.
Please note that your site should also look good with no JS or CSS, if nothing else it is good for Bots.
As others have pointed out some phones don't have JS, this is changing but another good reason to have reasonable non-JS. I suggest code with non-JS and add JS after the former works, there are good ways where JS can work with the non-JS layout.
It helps me in my implementations to think about it as "progressive enhancement" rather than graceful degradation. Degradation often leads you to figure out how to make it work w/o js after it is implemented, instead of making a baseline and enhancing with js.
It is essential to at least test your website is functional when JavaScript is turned off.
As orip says, degrading gracefully is very important. It should be vital that your page both looks nice and functions when JavaScript is disabled.
For a standard web site that is primarily intended for conveying information, degrade gracefully always.
For web applications:
When building a web application for a standard internet audience, I would keep the three following facts in mind:
95%-97% of potential users will have JavaScript enabled.
At times established users will need to access functionality when JavaScript is not available.
3%-5% of potential users will have JavaScript intentionally disabled.
Given fact one, if you believe that building a JavaScript reliant web application will deliver a superior user experience, then by all means do it. Doing so may help you accumulate users.
However, given fact two, you should always provide a means by which your users can access core functionality without JavaScript. Do you need to offer every single feature? Probably not. But a user should be able to get his or her work done. This will keep your users happy when they find themselves temporarily without JavaScript.
Given fact three, I would also provide an in depth tour as an attempt to entice these users to enable JavaScript.
As an aside, one of my most favorite web applications, Remember The Milk follows this approach. Also, Google's Calendar application is unusable without JavaScript. So JavaScript reliant web apps are on the rise and that trend is probably unstoppable. In my opinion this is a good thing.
(Do keep in mind that JavaScript make Accessbility a bigger problem than it is already. Please do make an effort to make your apps usable by those with disabilities.)
As said before, it depends on your target audience.
If I'm part of it, you want to make sure that your site works (if not ideally) on my phone, and that it gives me reason to turn Javascript on when I surf there with it off. Nobody expects full functionality with Javascript disabled, and anybody who uses their phone to access websites expects some issues, but you need to at least provide teasers. For a web store, make sure customers can see at least some merchandise anyway, even if they can't buy without Javascript.