Firefox not displaying dynamically embedded flash? Page-speed might be your problem!

Posted in Flash, Javascript | 1 Comment

Flash no show

Today i discovered a worrying bug with Firefox, Firebug and Page-speed.  A good friend of mine, Chris Murray, was demonstrating his new flash photo upload applet. I rudely pointed out that it didn’t work in Firefox only to find out that it did in his. After wasting his time trying to prove SWFOject, Firefox and maybe Flash needed to be updated it turns out that no dynamically embedded flash worked in my version of Firefox. Sorry Chris… What do i mean by embedded flash? Well, to get round the various methods of embedding flash into multiple browsers, javascript is often used to insert the flash into the DOM. Thereby using different techniques per browser. To cut a long story short here is a screenshot of the relevant flash: pageSpeedFlash As you can see, the mark up is correct and present, just strangely disabled. I am using Firefox 3.5.3, Firebug 1.4.3 and Page-speed 1.3. All are the updated and most recent versions.

What can you do?

Nothing really. The issue has been raised with Page-speed guys and there is a support thread too. I expect this to be resolved straight away as the issue has been marked critical. It is probably best to disable Page-speed for the time being. There is always Yslow!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: ,

Seperate a number (int) from string using Mootools

Posted in Javascript | No Comments
I recently blogged about using regular expressions to extract a number or integer from a string in javascript. So what if you are using Mootools? Well you save even more time:
//only works for a string beginning with a number!
('123 Hello World').toInt();  //=> '123'
Mootools FTW!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags:

Seperate a number (int) from a string in Javascript

Posted in Javascript | No Comments
Seperating a number or integer from a string is a common task in any coding language including javascript. It’s one of those times when you just wish code knew what you were trying to do… Imagine you have a string:
var myString = "123 Hello World";
I was in the middle of some mootool’in and i was about to go down the usual route of:
var myNumber = myString.substring(0,myString.indexOf(' '));
when i rushed off to google a better way to do it. Thanks to stackoverflow i found it. Regular expressions! I have no idea how to write them but i can appreciate them. The following expressions get the first integer within a string:
("123 Hello World 4").replace(/(^\d+)(.+$)/i,'$1'); //=> '123'

//If it's somewhere in the string:

(" Hello 123 World4").replace( /(^.+)(\w\d+\w)(.+$)/i,'$2'); //=> '123'

//And for a number between characters:

("Hello123World 4").replace( /(^.+\D)(\d+)(\D.+$)/i,'$2'); /=> '123''
Good stuff!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Detect Internet Explorer 6 (IE6) and other popular browsers with Mootools

One of the top keyword searches on this blog is ‘detect ie6 mootools‘; As popular as this search term is, it’s not actually covered, so this post should fill that gap! Mootools is a great, stable, open source javascript library which is maintained by a limited number of proffesional developers. It does have a browser detection class built in but it doesn’t natively provide a method to detect the version of Internet Explorer. The Mootools developers are code purists; Extending their browser class would be easy but they do not want to do it. They do provide a method to get the browser build and this could be used along with the remaining browser string to work out the version. Essentially, they like to keep their code relevant and streamlined. In a previous post i covered how to detect IE6 with one line of Javascript. This solves the problem where later builds of IE6 can show a browser string similar to IE7. This can be combined with the Mootools browser class to produce browser variables.
//declare global variables
var WEBKIT = Browser.Engine.webkit;
var GECKO = Browser.Engine.gecko;
var OPERA = Browser.Engine.presto;
var IE = Browser.Engine.trident;
var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
&& (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);

//test variables (delete)
if(WEBKIT) alert("WEBKIT");
if(GECKO) alert("GECKO");
if(OPERA) alert("OPERA");
if(IE) alert("IE");
if(IE6) alert("IE6");
Placing this code at the top of your JavaScript include will give you simple global boolean variables for each browser platform. Creating one variable per browser at the very start means the calls to the browser class are limited to one and the detection script is ran only once. It also means you have very simple and easy to remember variables to use throughout your code.
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: , ,

Diana takes one for the team – facebook username mischief

This story has flown around the internet today via social networks such as Digg, Reddit, Twitter and Facebook. It’s one of those situations where you just can’t help laughing at someone in an unfortunate situation. If this doesn’t make you laugh you really don’t have a sense of humour… … maybe you should add Diana as a friend. It started as a Reddit thead: Facebook girl “loves an*l” but apparantly doesn’t know it Basically, to some up, someone who is probably close to Diana has been able to access her account and choose her username. They chose ‘I Love An*l’. Now, if you type in http://www.facebook.com/i.love.anal you go to her page. I am, of course, assuming she didn’t do it herself. The original person who found this out was good enough to try to tell her… diana_legend This didn’t go down too well! Reddit also became aware of how much publicity the thread achieved. A new one was started up pointing out the results if you Googled the girls name. Reddit has now removed the above picture as the joke ‘went too far’. They were probably right, everyone was queuing up to tell Diana what has happened. She will almost certainly be a well know name for at least the next 24hours. Just goes to show what happens if you leave yourself logged in somewhere. (please note i have not mentioned her name anywhere in this article, i’m assuming facebook will change her username very soon, hopefully she will soon fall back into obscurity) So, pick your usename name! http://www.facebook.com/username Facebook should have done this from the start! or you could end up like these people (found via the reddit thread): http://www.facebook.com/cumonmyface http://www.facebook.com/cock.eater http://www.facebook.com/gayer
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: , ,

Font stacks, the !important css declaration and some html tips

Posted in CSS, Web Design | No Comments
It’s been a good week for subscribing to blogs, they are a endless stream of new and useful information, here are a few good tit-bits from my reader account!

Font Stacks

It’s a basic CSS declaration but not many people are aware of what font stacks do. In a world where most fonts are not available on the web, or ‘web-safe’ as we like to call it, you have to stick to a limited amount. Luckily CSS enables the developer to list his ideal fonts in an order of preference. Therefore if the first font, or most ideal, isn’t available then the next one will take over. This is called the font stack. Unit Interactive wrote a great article about font stacks and also created a downloadable PDF document with examples. This is a great tool to help explain to designers what is possible in true web design. As many developers will know, you typically get a PSD file from a designer and find you have to go back to them to explain why they can’t use a certain font. via firstwebdesigner.comCSS Globe

!important CSS Declaration

Impressive Webs – everything you need to know about the !important CSS declaration This is another great article which explains a common CSS declaration. CSS, by it’s nature, is cascading or in other words heiracial. This basically means it sets properties as it is read from top to bottom. A duplicated selector further down the page will overwrite the previous properties (where properties match). There are also instances where someone has used in-line styling or you have no choice but to use in-line styling (i can’t think of one). ‘!important‘ can also overwrite this! Typing ‘!important‘ after any CSS property tells the browser that this CSS declaration is the most important one and overwrites all other declarations. It is great for overwriting common classes or properties where you might want to use an exception or perform a minor tweak. via CSS Globe

Finally, some good html tips

Line25.com – html crimes you shouldn’t commit This article provides a quick list of 10 html good practices which would improve your coding. The majority are straight forward and known to many, the most being about out-dated tags, but still it’s great to see a blog going back to the basics. One great thing about using the more updated tags is that you can wrap the older tags around html elements, reset them with CSS (font-weight:normal), and use them together with a Javascript frame work to create advanced effects!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags:

Save IE6 – if only Internet Explorer 6 was as good as this site

Save IE6 screenshot Just like every other web designer i can’t wait for Internet Explorer 6 to be gone. There are some people who do not share this view. Maybe IE6 does have some good points. Just maybe it might be worth saving… visit Save IE6 Ha! Tongue is definately in cheek. Forget about IE6 for a second and you are looking at a nice site, it even works perfectly in IE6. Check out the download link where you are forced to complete a compatibility test first and then sign the petition. I’d like to think the writing is on the wall for IE6 and that it won’t be around for much longer. In that case it really does need your help. Let’s hope it’s too late!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: ,

Did you notice it’s the 1st April – a round up of some of the best hoaxes

What is April Fools?

Every year on the 1st of April it is traditional to try to April fool somebody before the clock strikes midday. To do this you simply have to convince your gullible friend or colleague about a fictional or misleading non-truth. Basically you feed them the most unbelievable hoax, laugh at them when they fall hook, line and sinker and finally give them a pinch and a punch (for the first of the month) for their troubles. The day itself is a bit of a mystery even Wikipedia doesn’t give a definite answer. The best guesses include the name given to fools who plant their crops too early or people who kept to the old calendar where the year started in April not January. Either way it makes a great excuse for some fun.

Ok so what happened today?

It seems every year the web design community get more and more involved with April Fools day hoaxes. Today was no exception; gmail autopilot Gmail announced an Autopilot feature to auto-respond to those annoying messages. It is ran by CADIE google’s Cognitive Autoheuristic Distributed-Intelligence Entity who has it’s/his/hers one blogger homepage and favorite places! google-chrome-3d Google Chrome release their new 3D plugin smashing magazine ie8_eagle_eye Smashing Magazine introduced IE8 Eagle Eye the all conquering update (they got in their nice and early too) flip-youtube Youtube went all Ozzie on us jtools - mootools Mootools announced a new name Opera announced a new feature called face gestures! sitepoint-reboot Sitepoint announce the impending reboot of the internet at 11:59am guardian-twitter The Guardian switches to a twitter only news feed naked-developer-day silktidestudios Silktidestudios announced the second National Naked Developer Day! expedia-mars Expedia sell flights to mars! coin-phone Dial a Phone sell a coin and card operated phone thinkgeek-bacon-unicorn Thinkgeek announce an array of amazing products including a unicorn chaser and squeez bacon! uk-wii The Uk government plan to give out free Wii Consoles kodak-eyecamera Kodak launch the genius eyeCamera Microsoft launches a Alpine Legend game controller? Some people have far too much time on their hands! Brilliant none the less! Roll on next year!
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Google Analyitics – fix the ‘_gat’ is undefined problem in IE6 with Mootools

Google Analytics is a fantastic, totally free, web tracking service provided by Google. It works by embedding a Javascript include at the bottom of your page which loads Google’s tracking code. The code then passes all your tracking information to the Analytics cloud where it is digested and returned in the web-app.

The Problem

The code has to be included just before your closing body tag, this is because Google doesn’t want to hold up your page loading while it crunches this data, by placing it there it guarantees 99% of your page has finished loading. This works perfectly in almost all cases but there have been exceptions. The only time i have come across a problem was when i was testing a site on Internet Explorer 6. I kept receiving this error:
'_gat' is undefined
This can only be created when the code tries to call the Analytics code before it is launched. Basically, it’s is trying to call the function _gat too soon. Google have tried to fix this by adding a Javascript ‘try’ function.
<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	try {
		var pageTracker = _gat._getTracker("UX-XXXXXX-X");
		pageTracker._trackPageview();
	} catch(err) {}
</script>
This helps as the code ‘tries’ to run the function and if it can’t then it runs the catch command. This works because it doesn’t create any other errors and the site will continue operating normally. The only problem is no tracking information will be passed.

Fixing it with Mootools

Firstly, more and more websites are using Javascript to provide better interactivity and functionality so there is a good chance you are already using a library in your site. Secondly they provide core functions which can detect when the page’s DOM is ready and when the page itself has actually finished loading. There a couple of things that can improved by converting this code to use a popular Javascript framework such as Mootools. Page load speed should be improved as we try to insert the tracking code after the page has completely finished loading and has been initiated. As a result we can also hope to improve the code performance by making sure the code has been downloaded before trying to run it. Using Mootools we simply add a new Javascript assets into the page using the ‘addEvent’ function and then run the analyitics function calls when it has loaded.
window.addEvent('load', function() {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	new Asset.javascript(gaJsHost + "google-analytics.com/ga.js", {
		onload: function() {
			try {
			var pageTracker = _gat._getTracker("UX-XXXXXX-X");
			pageTracker._trackPageview();
			} catch(err) {}
		}
	});
});
As you can see, I have left the try function in, this is to protect against the same problem we faced initially. Only this time the chance of it happening has greatly reduced. Another benefit of using this method is that you can remove the tracking code from your HTML template or masterpage. Now it is simply added into your Javascript include instead. If you use analytics to track your AJAX calls then it helps that all your code is in the same place! I hope you find this useful, please leave a comment if you know of any improvements or think you know a better method.
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: , , ,

Flash Quick Tip: How to randomize an Array

Posted in Flash | 2 Comments
I had to google this today so i though i would share it with you! This snippet of actionscript can be used to simply re-order or randomize an array in Adobe Flash.
var myArray = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
myArray.sort(function (){
return Math.round(Math.random());
});
trace(myArray);
ps and yes i know I’ve spelt randomise wrong ; )
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Tags: