admin管理员组

文章数量:1332395

In a web application, writing javascript is a mon work, and I have tried to create cross-browser code.

If I try my best to make it work in Firefox, then it does not work in IE.

So I wonder if there are any rules or experiences from you guys to tell me how to write cross-browser code?

UPDATE:

Sorry I forget to make it sure that we can not use jquery in my current application since we are usng prototype1.4(which is to difficult to use than jquery),so most time we use the native javascript.

In a web application, writing javascript is a mon work, and I have tried to create cross-browser code.

If I try my best to make it work in Firefox, then it does not work in IE.

So I wonder if there are any rules or experiences from you guys to tell me how to write cross-browser code?

UPDATE:

Sorry I forget to make it sure that we can not use jquery in my current application since we are usng prototype1.4(which is to difficult to use than jquery),so most time we use the native javascript.

Share Improve this question edited May 14, 2011 at 12:52 hguser asked May 14, 2011 at 12:36 hguserhguser 36.1k55 gold badges172 silver badges302 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 6

The vast majority of problems will go away if you:

  • Have a Doctype that triggers standards mode
  • Follow the specifications and avoid proprietary browser extensions

Most of the rest will go away if you use a library that abstracts away the differences. There are plenty of small specialized ones as well as kitchen sink options such as YUI and jQuery.

Have you tried jQuery? It's a great cross-browser JavaScript library that's very popular for JavaScript development.

I would use any of the plethora of js libraries out there, such as jquery, sencha, sproutcore, etc.

They go thru great pains to make cross-browser issues null and void. You always need to test in al browsers that you want to support, but these libraries are excellent and do most if not all of the work for you.

I'd remend CoffeeScript - http://jashkenas.github./coffee-script/

It allows you to write in a safe way without worrying about global vars and all the quirks of JS. It's worth a look.

Have you tried to use jQuery?

It would allow you to isolate your own javascript code and write cross-browser code

本文标签: How to write crossbrowser javascript codeStack Overflow