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

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 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

Browser detect for IE versions

// is called when you want to test which version of IE a user has, returns true or false

function isIE(versionNumber) {
var detect = navigator.userAgent.toLowerCase();
if(!(navigator && navigator.userAgent && navigator.userAgent.toLowerCase)) {
  	        return false;
  	    } else {
  	        if(detect.indexOf('msie') + 1) {
  	            // browser is internet explorer
  	            var ver = function() {
  	                // http://msdn.microsoft.com/workshop/author/dhtml/overview/browserdetection.asp
  	                // Returns the version of Internet Explorer or a -1
  	                // (indicating the use of another browser).
  	                var rv = -1; // Return value assumes failure
  	                if (navigator.appName == 'Microsoft Internet Explorer') {
  	                    var ua = navigator.userAgent;
  	                    var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  	                    if (re.exec(ua) != null) {
  	                        rv = parseFloat( RegExp.$1 );
  	                    }
  	                }
  	                return rv;
  	            };
  	            var valid = true;
  	            // if the version can be found and the version is less than our version number it is invalid
  	            if ((ver > -1) && (ver < versionNumber)) {
  	                valid = false;
  	            }
  	            return valid;
  	        } else {
  	            return false
  	        }
  	    }
} 

Turn off image buttons / icons on your pages in IE

Turn off the image buttons (when you hover over an image) and Smart Tags in IE:

<meta http-equiv="imagetoolbar" content="false" />
<meta name="MSSmartTagsPreventParsing" content="true" />

IE Automation in Python

I try to dump my data out of a website. But it block my python's urllib bot. I tried other pure python libray but without success. So, I try a quicker route using IE automation.
For general automation you should try 'watsup'. For IE, there is PAMIE.
>>> from cPAMIE import PAMIE
>>> ie = PAMIE()
>>> ie.Navigate('www.google.com')   # go to google
>>> ie.SetTextBox('Python','q',0)       # search for python
>>> ie.ClickButton('btnG')               # Go!

>>> src = ie.pageText()                 # here it is
>>> cookie = ie.GetCookie()          # Ok, cookie is yummy


PAMIE is actually aimed for more of the testing work.
But in this case it serves me fine.
http://pamie.sourceforge.net/
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS