Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Matt Scilipoti

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Cross browser compatibility tip: Conditional Compile in IE

From: http://www.javascriptkit.com/javatutors/conditionalcompile.shtml
Conditional Compilation of JScript/ JavaScript in IE

In IE, there is a little known feature called conditional compilation. Supported since IE4, this feature starting getting some attention when it began showing up in some Ajax related JavaScripts. An absolute form of object detection, conditional compilation lets you dictate to IE whether to compile certain parts of your JScript or JavaScript code depending on predefined and user defined conditions. Think of it as conditional comments for your script that can also be molded to work gracefully with non IE browsers as well.

Thanks to: http://www.vivabit.com/bollocks/2006/04/06/introducing-dom-builder#c856

#48: Avatar kentaromiura / 19th April '06

You could do like I do here: Crazy corners using IE conditional comment
var cn=�class�;

/@cc_on

cn="className";

@/

so you use cn insted of class or classname _; bye

Prototype and window.onload

from: http://happygiraffe.net/blog/archives/2006/03/05/prototype-and-window-onload


We’ve known for some time that simply assigning to window.onload is bad. Simon Willison created addLoadEvent a long time back to work around the problem. But I’m in Rails, and we have prototype. So what’s the correct idiom?

Well, after a bit of playing, it seems to be this:
  <% content_for("page_scripts") do %>
    Event.observe(window, 'load',
      function() { $('username').focus() }
    );
  <% end %>

I do love that $() function.

This assumes that you have a layout that looks something like this, in order to insert bits of JavaScript into the head.
  <script type="text/javascript">
    <%= @content_for_page_scripts %>
  </script>

Anyway, the solution seems a little more verbose than addLoadEvent(), but not disastrously so.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS