Internet Explorer “Unspecified Error” with jQuery and getBoundingClientRect

Posted: May 8th, 2010 | Author: | Filed under: Web Development | Tags: , , , , , , | 1 Comment »

I’ve been getting “Unspecified Error” errors from Internet Explorer with some jQuery code. I traced the cause to jQuery’s “getBoundingClientRect” which comes from a call to $(…).offset({top: X, left: T}).

After looking around in some forums/blogs, it seems the error is coming from some handling of internet explorer with offsetParent in some specific cases. to be honest, I don’t really understand what happens there…

But I did manage to fix it by simply calling $(…).css({top: X, left: Y}) instead of $(…).offset({top: X, left:Y}), which does pretty much the same in my case.

Just thought someone out there might find it useful…


jQuery shake() function

Posted: December 29th, 2009 | Author: | Filed under: Web Development | Tags: , | No Comments »

I needed a quick function for jQuery to shake an absolute or static positioned (can be easily modified to support other positions too, but it doesn’t at the moment) element up&down that isn’t depended on jQuery UI (I’m using to shake simplemodal‘s container).

This is what I came up with that:

(function($){
	$.fn.shake=function(opt){
		opt=$.extend({times: 8,delay: 150,pixels: 20},opt||{});
		$(this).each(function(){
			var orig=parseInt($(this).css('top'));
			for (var i=0; i

Its usage looks like that:

$('#simplemodal-container').shake({times:8, delay:150, pixels:20});

All the parameters are optional, you could simply call $(..).shake() to use the defaults values or overwrite just some of the them.

times determines how many times to shake the element, delay is how long each animate() call should take, and pixels is the number of pixels to move up/down every time


CSSJanus: Convert LTR CSS to RTL

Posted: December 25th, 2009 | Author: | Filed under: Web Development | Tags: , , , , | No Comments »

I found CSSJanus couple days ago, an online tool that attempts to change CSS from left-to-right to right-to-left, by changing properties like text-align, float and direction from “left” to “right”, “ltr” to “rtl” (and vice-versa), dealing with CSS properties that has “something: top left bottom right” (like margin: 10px 5px 1px 3px), and also some less obvious properties that effects text/layout direction/alignment.

It does quite a good job – converting LTR to RTL is 90% done (and completely done in some cases) after using it, there are some changes that must be made manually sometimes – but starting off with this is a great start who saves most of the job.

CSSJanus was written by Lindsey Simon (who works at Google) in Python. More information can be read at the Google Opensource Blog and the code can be obtained at Google Code.

A video showing the developer, explaining about it and showing it in action:


How to create a link that doesn’t send a referrer header

Posted: December 25th, 2009 | Author: | Filed under: Javascript, Web Development | Tags: , , , , | 1 Comment »

I was looking for a way to create a link that won’t send a referrer header at all, for my torrentz.com greasemonkey script (some trackers didn’t like other sites linking directly to their .torrent file), and came up with that (with the help of a Christmas present from anonymous).

It should work on all browsers who supports the data: URI schema with navigable content, which means it won’t work on Internet Explorer 6, 7 (who doesn’t support the data URI at all), 8 (who doesn’t allow navigable content) or old versions of other browsers (one of the great things about writing a Greasemonkey script is that you don’t have to care about any browser other than Firefox). it might work with about: uri on IE6/7, but it wasn’t tested.

Tested on Firefox only, Chrome and Safari.

It works by linking to a data URI that creates a page with some HTML (<html><head><meta http-equiv=”refresh” content=”0;url=http://www.whatismyreferrer.com/”></head></html>) in it:

<a href='data:text/html;charset=utf-8,<html><head><meta http-equiv="refresh" content="0;url=http://www.whatismyreferrer.com/"></head></html>'>Click me</a>

What happens is that you link to a virtual page who redirects to the target URL, so the actual page that made the redirect is the virtual page and not your site (and the browsers doesn’t send the data: URI as the referrer).

Try it in comparison to a regular link

Here’s the function I used to create those links using  javascript:

var noreflink=function(href) {
	return 'data:text/html;charset=utf-8,'+encodeURIComponent('<html><head><meta http-equiv="refresh" content="0;url='+href.replace('"','&quot;')+'"></head></html>');
}

Also,

document.location=noreflink("http://www.google.com/");

can be used to redirect using javascript without sending a referrer, instead of using a link.

Update: This won’t work on Opera. when using a meta refresh it still uses the URL that linked to the page with the meta refresh as the referrer header. I tried using javscript redirect (document.location) instead, and even with a timer – it doesn’t work.

I did find a working solution for Opera eventually:

does the trick, and the link will look like:

Click me

Try it here

However, that works for Opera only. There’s a way to make a version that’ll work on all browsers (except IE), but because I only needed it for a Greasemonkey script and I don’t care about any browser other than Firefox, I’ll leave that for you. If anyone do write a cross-browser version, add it as a comment and I’ll update the post.