Archive for the 'Web Development' Category

Controlling the IE7 “Shrink to Fit” print setting using JavaScript

Friday, November 30th, 2007

You may have noticed that printing in Internet Explorer 7 has a new feature - "Shrink to Fit". In some situations, such as when pages are in an iFrame, "Shrink to Fit" is always applied by default. For general web pages this feature may be appreciated, but in a web application where developers want to control the layout of the page, and perhaps generate reports, we do not appreciate IE7's changing the print layout at all.

If you have not been challenged by this behaviour yet, don't worry - you will! And when you do, here is the solution.

Instead of the typical "print()" command in JavaScript, use:


document.execCommand('print', false, null);

Or if you are wanting to print a document inside an iFrame you can use something like:


window.frames(0).focus();
window.frames(0).document.execCommand('print', false, null);

Note: This solution is for Internet Explorer 7 only - I leave it up to you to do the browser detection.

Debugging in Zend Studio without Zend Platform

Monday, June 4th, 2007

I have been using Zend Studio for quite a while now as my primary PHP IDE. To get the powerful remote debugging and profiling that comes with the tool you used to have to install Zend Studio Server as well. With the release of version 5.5 however, Zend stopped shipping Studio Server and forced developers to install the Zend Platform instead. This is a commercial tool (free to developers) available from Zend that offers PHP acceleration, caching and other features … that I don't want! I just want my debugging back, without having to bloat my local server with software I will not use elsewhere - especially when the Zend Platform does not support APC, which we run on our servers, and it also broke my web application.

It turns out that we do not need the Zend Platform at all. As part of the PDT Eclipse project Zend has made available a standalone version of their debugger. This can be downloaded from here: http://downloads.zend.com/pdt/server-debugger/

Then you just need to put the .so or .dll file in the correct location and add a few lines to your PHP.INI file and you are away. Here are the lines I had to add to my PHP.INI, which is running inside a Debian VMWare image. Note the commas separating the IP numbers - this took me a few goes to work out as the examples showed spaces or forward-slashes which didn't work for me.

zend_extension=/etc/Zend/ZendDebugger.so
zend_debugger.allow_hosts=192.168.1.3,192.168.220.1,192.168.150.1,127.0.0.1,192.168.220.10
zend_debugger.expose_remotely=always

Why did Zend make this so hard to work out? Reading on different blogs and through the Zend forums highlights that this issue has been a source of frustration for many developers. Grrrr…

Google Gears Enables Disconnected Web-Apps

Thursday, May 31st, 2007

Google Gears is an open source browser extension, less than 1Mb in size, that lets developers create web applications that can run offline. There are two main ways the extension can be used - by embedding the API or runtime software in an application you distribute to end users, or by writing a web application which makes use of installations of Gears on end-users' computers.

What problem does it solve?

Web developers write software for … the web. For applications that run via a browser that is connected to the Internet. Google Gears will take web applications to the desktop - enabling Web applications to work offline. A user will not be required to be connected to the Internet to use the application.

How does it work?

First of all web applications will need to detect whether or not Google Gears is installed on a user's machine. If Gears is installed, then the application will be able to access the Google Gears APIs from JavaScript code. If Gears isn't installed, the user can be directed to a customized installation page.

The APIs can then be used to access Google Gears three core features:

  • A local server, to cache and serve application resources (HTML, JavaScript, images, etc.) without needing to contact a server.
  • A SQLite database, to store and access data from within the browser.The Database module is used to persistently store an application user's data on the user's computer. Data is stored using the same-origin security policy, meaning that a web application cannot access data outside of its domain. Standard SQL can be used to access the data, and full-text indexing is supported using SQLite's fts2 extension.
  • A worker thread pool, to make web applications more responsive by performing expensive operations in the background. In web browsers a single time-intensive operation, such as I/O or heavy computation, can make the UI unresponsive. The WorkerPool module runs operations in the background, without blocking the UI.

What browsers are supported?

The final release will run on the following browsers:

  • Apple Mac OS X (10.2 or higher)
    • Firefox 1.5 or higher
    • Safari
  • Linux
    • Firefox 1.5 or higher
  • Microsoft Windows (XP or higher)
    • Firefox 1.5 or higher
    • Internet Explorer 6 or higher

What next?

To find out more about this project you can visit the Google Gears website. From there you can download Gears and then install some of the sample applications available.

Some developers are already playing with Google Gears and sharing their experience and their plans. For example you can listen to a podcast about Dojo Offline being ported to Google Gears, or take a look at RSS Bling moving to Google Gears.

This is definitely a project to watch. With Google obviously coordinating with the efforts of popular projects such as Dojo, as well as supporting all the major browsers, there are some interesting possibilities opening up for web applications.

Linus Upson, the engineering director at Google, stated that the goal of Google Gears is to "create a single, standardized way to add offline capabilities to Web applications." Google is certainly on the right track … I'm off to have a play!

Generating Random Sample Data

Tuesday, April 17th, 2007

I found a very useful tool today - the Data Generator. It generates large volumes of random, custom data for use in testing software. The tool is a free download, and can generate data in the following formats:

  • HTML
  • Excel
  • XML
  • CSV
  • SQL

There is an online demo available that is limited to 200 results. Click here to find out more…

Firebug 1.0 - A “Must Have”

Tuesday, December 5th, 2006

It's been over 10 months since I first started advocating Firebug, especially for developers working with AJAX. Since that time the tool has been rewritten from scratch and been given a lot more focus by the developer Joe Hewitt. The result is Firebug 1.0.

The core features of 1.0 include CSS editing, network load timing, box model visualization, JavaScript profiling, command line autocomplete, HTML change highlighting, debugger watch lists, DOM editing, separate window support, and per-site blacklists.

Firebug is now one of the most used and appreciated tools in my developer toolbox. If you have not downloaded the 1.0 beta then here are some compelling reasons why you should…

Just the way you like it

Firebug is always just a keystroke away, but it never gets in your way. You can open Firebug in a separate window, or as a bar at the bottom of your browser. Firebug also gives you fine-grained control over which websites you want to enable it for.

Learn more

Inspect and edit HTML

Firebug makes it simple to find HTML elements buried deep in the page. Once you've found what you're looking for, Firebug gives you a wealth of information, and lets you edit the HTML live.

Learn more

Tweak CSS to perfection

Firebug's CSS tabs tell you everything you need to know about the styles in your web pages, and if you don't like what it's telling you, you can make changes and see them take effect instantly.

Learn more

Visualize CSS metrics

When your CSS boxes aren't lining up correctly it can be difficult to understand why. Let Firebug be your eyes and it will measure and illustrate all the offsets, margins, borders, padding, and sizes for you.

Learn more

Monitor network activity

Your pages are taking a long time to load, but why? Did you go crazy and write too much JavaScript? Did you forget to compress your images? Are your ad partner's servers taking a siesta? Firebug breaks it all down for you file-by-file.

Learn more

Debug and profile JavaScript

Firebug includes a powerful JavaScript debugger that lets you pause execution at any time and have look at the state of the world. If your code is a little sluggish, use the JavaScript profiler to measure performance and find bottlenecks fast.

Learn more

Quickly find errors

When things go wrong, Firebug lets you know immediately and gives you detailed and useful information about errors in JavaScript, CSS, and XML.

Learn more

Explore the DOM

The Document Object Model is a great big hierarchy of objects and functions just waiting to be tickled by JavaScript. Firebug helps you find DOM objects quickly and then edit them on the fly.

Learn more

Execute JavaScript on the fly

The command line is one of the oldest tools in the programming toolbox. Firebug gives you a good ol' fashioned command line for JavaScript complete with very modern amenities.

Learn more

Logging for JavaScript

Having a fancy JavaScript debugger is great, but sometimes the fastest way to find bugs is just to dump as much information to the console as you can. Firebug gives you a set of powerful logging functions that help you get answers fast.

Learn more

Click here to download the Firebug 1.0 beta…

Afraid of CSS and Standards?

Thursday, September 28th, 2006

If you are, then take comfort in the fact that you are not alone. Here is an excellent article covering some of the frustrations of moving from table-based layouts to pure CSS. I could relate to a lot of the article's content - maybe you can too…

Issue One of Visual jQuery Magazine Released

Saturday, September 23rd, 2006

Visual jQuery Mag - Issue OneI have posted a number of times about jQuery - a JavaScript (JS) framework that will revolutionise the way you write JS. The community uptake of this framework has been quite impressive. Now there is even a monthly magazine available, courtesy of Yehuda Katz. The first release of the magazine includes the following topics:

  • an editor's note about the magazine
  • a profile of jQuery's founder, John Resig
  • an introduction to jQuery's basic principles
  • an argument for jQuery's philosophy
  • an interview with the creator of the jqMinMax plugin, Dave Cardwell
  • a roundup of three plugins that are useful for creating rich web applications

Why is this framework worthy of so much attention? You need to be a JavaScript coder to really appreciate it's beauty. Basically jQuery allows web developers to write JS the way we think, the way we see the world within the context of the DOM. Not only is it logical and simple to work with, it will drastically reduce the amount of JS you write. That means smaller files, your code is easier to read and understand, and you spend less time coding. It enables you to easily work with AJAX, animations, forms, CSS, and the list goes on - all for including a file only 16k in size.

On top of that, the jQuery community is rapidly adding new plugins and widgets that work with jQuery. The mailing list is also extremely responsive and helpful.

Once upon a time the developer world went crazy about Prototype and Scriptaculous. For me jQuery and Interface leave such alternatives in the dust. Why? Apart from the fact that jQuery+Interface = 66k (16+50) and Prototype+Scriptaculous = 188k (50+128)? jQuery and Interface are just more intuitive to work with and offer the same core features.

Here are some links to get you excited:

Anyway - it is time for me to stop raving. If I keep posting only about jQuery this blog is going to get fairly monotonous! I will now leave you to form your own impressions…

It’s Been A While…

Saturday, August 19th, 2006

As regular visitors to this site will have noticed I have not posted any articles for a while. But I am still alive and well! My wife and I have successfully relocated to Wellington, New Zealand, and I am now settled into my new role as Systems Delivery Manager for Database Communications.

I have been working on some pretty interesting projects for companies like BP, Castrol, and Australia Post. The projects have involved the use of several of the tools I have discussed on my weblog over past months. In particular I have been actively using jQuery and the Zend Framework and highly recommend them as a key part of any web developers toolkit.

So … now that I have shown my face again I hope I can return more often. In the meantime, perhaps you would be interested in reading a new 18 page tutorial to help get started with the Zend Framework. Or maybe you would like to check out the new improved jQuery website (still in beta) and some of the great jQuery plugins that have been released over recent weeks.

Until next time…

Lucene and the Zend Framework

Thursday, April 27th, 2006

Zend FrameworkOne of the most talked about features of the Zend Framework is its port of the Apache Lucene project - a Java-based full-text search-engine framework. The Zend Framework allows PHP developers to use Lucene without requiring additional PHP extensions or Java, or even a database.

The theory is that Zend_Search_Lucene overcomes the usual limitations of relational databases with features such as:

  • Fast indexing
  • Ranked result sets
  • A powerful but simple query syntax
  • The ability to index multiple fields

Lucene is well-known for it's speed. For an example have a look at DamnFastDotLucene - this demo site tests the performance of a .Net implementation of Lucene on quite a large set of documents:

  • 9150 text files from the Gutenberg Project
  • The total size of indexed documents is 3.5 GB
  • The index size is 880 MB
  • The Hardware: Pentium 4 3Ghz 800/1MB Cache, 1 GB DDRII Kingston 533, Western Digital Raptor 80GB

The result - it takes approximately the same time to search 5 MB of text as it does to search 3.5 GB of text. I was getting speeds less than 0.125 seconds. That is fast.

That was .Net though - what about the PHP implementation in the Zend Framework?

The reality for PHP developers using the Zend Framework may be a little different from the hype. Some developers are reporting Zend_Search_Lucene as being significantly slower than the queries being run from MySQL or PostGres. Have a look at the following comments in the Zend Framework Mailing List for details.

To be fair it is only very early days for the Zend Framework and Lucene - the project is still in early Alpha. However it is already being adopted by the community for live projects.

If you want to learn more about Zend_Search_Lucene I recommend the following links:

If you have any experiences with Zend_Search_Lucene that you would like to share I would appreciate hearing about it…

Web Developer Toolbar for Internet Explorer 6

Sunday, March 26th, 2006

Internet Explorer LogoWell … it's not as good as its counterpart for Firefox, but it is certainly a useful tool for web developers. The Internet Explorer Developer Toolbar from Microsoft offers the following features:

  • Explore and modify the document object model (DOM) of a Web page.
  • Locate and select specific elements on a Web page through a variety of techniques.
  • Selectively disable Internet Explorer settings - Cache, Cookies, Images, Scripts, Popups.
  • View HTML object class names, ID's, and details such as link paths, tab index values, and access keys.
  • Outline tables, table cells, images, or selected tags.
  • Validate HTML, CSS, WAI, and RSS Web feed links.
  • Display image dimensions, file sizes, path information, and alternate (ALT) text.
  • Immediately resize the browser window to a new resolution.
  • Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.
  • Choose direct links to W3C specification references, the Internet Explorer team weblog (blog), and other resources.
  • Display a fully featured design ruler to help accurately align and measure objects on your pages.

There is certainly an abundance of useful features for developers to play with. Enjoy…