I’m working on a small project for my company by rails and jQuery. The newest rails3 use many html5 features. So I decide let user use a modern browser to use my web page. Otherwise IE6 will kill me. How to switch smoothly? I found chrome frame has beta yesterday!
Someone said that they hate the web page of xxx-browser only. But wait! I use this in my company only! Didn’t you saw those enterprise-level soft let you install their plugin?
Make an IE-only page is easy. Make an IE-except page is easier. lol
Chrome frame show my html5 page (maybe). It’s beautiful than IE. But it cannot works when I send ajax request.
For example I write a link like this:
<!-- Rails html5 templete -->
But chrome frame look like send a incorrect request to rails. Check the log of rails, I found this line:
Processing by UsersController#new as */*
The right process method is JS because the data type is script. I have test IE FF Chrome and Safari on win and mac. Only chrome frame has this issus.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.62 Safari/533.4
But rails could detect the right user agent:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) chromeframe/5.0.375.62
<!-- Hold it in application.html.erb or ur own default layout. for this example put in navigator. -->
# Detect chrome frame in application_controller.rb
And then hack $.ajax. In fact I have three things need fix.
- Chrome frame cannot send PUT DELETE verb.
- Append .js to url tell rails I’m a JS request.
- jQuery will try parse the result as JSON when dataType is script. If it got html. You will see an error: “Uncaught SyntaxError: Unexpected token <”.
//BUGFIX: Chromeframe miss some features.