Jump to content

GT500

Members
  • Posts

    7
  • Joined

  • Last visited

About GT500

  • Birthday 10/22/1984

Contact Methods

  • Website URL
    http://www.gt500.org/
  • ICQ
    0

Profile Information

  • Location
    Indiana, USA

GT500's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Here's an even easier way of serving the proper doctype, ans it's even in PHP: <? if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")){ header("Content-Type: application/xhtml+xml; charset=UTF-8"); echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); } else { header("Content-Type: text/html; charset=UTF-8"); echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); }?> This simple PHP scriptlet also outputs the proper doctype as well. XHTML 1.1 if the browser supports application/xhtml+xml or XHTML 1.0 Strict if the browser does not. You can of course change the doctype declarations to whatever you want.BTW: This script complements of HTMLDog.com...
  2. If you really think about it, why would anyone need to view a page of Opera customizations using Internet Explorer?
  3. Use a simple server-side script to determine browser type. Here's what a simple server-side browser sniffer looks like in Java ServerPages (JSP):<%@ page import="java.util.StringTokenizer,java.util.Vector" %><% String browser = request.getHeader("User-Agent"); StringTokenizer tokenizer = new StringTokenizer(browser, " "); Vector userAgent = new Vector(); boolean containsOpera = false; boolean containsKonqueror = false; boolean containsFirefox = false; boolean containsIE = false; while (tokenizer.hasMoreTokens()) { userAgent.add(tokenizer.nextToken()); } for (int i = 0; i < (userAgent.size()); i++) { if ((("" + userAgent.get(i)).length() >= 5) && ((("" + userAgent.get(i)).substring(0, 5)).equalsIgnoreCase("opera"))) { containsOpera = true; } if ((("" + userAgent.get(i)).length() >= 9) && ((("" + userAgent.get(i)).substring(0, 9)).equalsIgnoreCase("konqueror"))) { containsKonqueror = true; } else if (("" + userAgent.get(i)).equalsIgnoreCase("msie")) { containsIE = true; } else if ((("" + userAgent.get(i)).length() >= 7) && ((("" + userAgent.get(i)).substring(0, 7)).equalsIgnoreCase("firefox"))) { containsFirefox = true; } } if (containsOpera && !(containsFirefox) && !(containsKonqueror)) {%><%@ include file="opera.txt" %><% } else if (containsKonqueror) {%><%@ include file="konqueror.txt" %><% } else if (containsFirefox) {%><%@ include file="firefox.txt" %><% } else if (containsIE) {%><%@ include file="ie.txt" %><% } else if (!(containsOpera) && !(containsKonqueror) && !(containsFirefox) && !(containsIE)) {%><%@ include file="other.txt" %><% }%> As you can see, it's fairly simple (at least in Java) to determine what browser someone is using, and then return the proper content. If you want to see it in action, the script is running here. The page is for customizations to the Opera browser (still a bit of a work in progress). I made it to give an offensive message if you are not using Opera when you view the page. It will only load the main content if it thinks you are using Opera.Say that you want to set a special content type based on whether the user is viewing the page in IE, or another browser. That would go something like this: <%@ page import="java.util.StringTokenizer,java.util.Vector" %><% String browser = request.getHeader("User-Agent"); boolean containsOpera = false; boolean containsIE = false; StringTokenizer tokenizer = new StringTokenizer(browser, " "); Vector userAgent = new Vector(); while (tokenizer.hasMoreTokens()) { userAgent.add(tokenizer.nextToken()); } for (int i = 0; i < (userAgent.size()); i++) { if ((("" + userAgent.get(i)).length() >= 5) && ((("" + userAgent.get(i)).substring(0, 5)).equalsIgnoreCase("opera"))) { containsOpera = true; } else if (("" + userAgent.get(i)).equalsIgnoreCase("msie")) { containsIE = true; } } if (containsOpera) { response.setContentType("application/xhtml+xml"); //Since Opera can send a user-agent string almost identical to MSIE6, it's best to sniff for it first. } else if (containsIE) { response.setContentType("text/html"); } else if (!(containsOpera) && !(containsIE)) { response.setContentType("application/xhtml+xml"); }%> To see that script in action, just navigate here. I'm sure it's just as simple to do that in PHP as well.
  4. Well, after messing around, and looking at the JavaScript that is handling everything, I saw that they account for 3 browser types. Opera, IE, and Mozilla (or Mozilla compatible). For Opera, you get a popup saying it doesn't work, for IE you get some ActiveX stuff, and for Mozilla you get standards compliant code.I've been messing with the UserJS in Opera 9, trying to get it to override the JavaScript file with one I modified to actually work. So far I have had no luck. I seem to have very little idea what I'm doing.Anyway, if someone from W3Schools actually sees this, all they have to do to fix the issue is replace the JS code for Opera with the code for Mozilla. They can both handle the same code.
  5. It's very true that web stats are not a reliable way to determine browser usage.It's also very true that web stats are specific to the domain. Just check out the stats from my site. My users tend to lean towards Opera and Linux...
  6. It would make for a much more usable website if possible compatibility issues were mentioned in a side note, instead of serving up broken code that tells you "This doesn't work", and then won't even let your browser attempt it.As an Opera 9 user, I have the ability to not only 'identify as' IE/Mozilla, but to fully mask as them (which can be done in Opera 8 by modifying the ua.ini file). That means that Opera gives the exact user-agent string of the browser it's pretending to be. The major problem with that is that the web server is no longer counting a hit from Opera. That means that there could be hundreds of Opera users on a website, but because of broken code, users are setting Opera to mask as something else. A webmaster would then have no idea that they had a large base of Opera users.
  7. I'm sure that this thread will not be looked upon kindly, as most people seem to dislike the Opera Web Browser. But I feel that it needs mentioned that the first example in the AJAX tutorial (http://www.w3schools.com/ajax/ajax_example.asp) works fine in Opera 9.This was brought to my attention after I posted on my blog that Opera didn't fully support AJAX, and posted a link to that example. I was quickly greeted by a friendly comment that if set up Opera 9's per-site preferences to mask as Mozilla at w3schoole.com that the example worked without error.When I tried this myself, I found that it was true. The example works fine in Opera 9. The only thing preventing it from working is the fact that the script that is served up for Opera is made to pop up a dialog saying it doesn't work, instead of actually trying to do it.At the very least, could the example be modified to serve up the same code for Opera 9 that it does for Mozilla?I would really like to learn and make use of AJAX. Unfortunetely, I despise using another browser, and the examples are made so that they won't even try to work in Opera.
×
×
  • Create New...