When Tim Burton brought Batman to the big screen in 1989 its said that Williams was being considered for the role of the Joker, before Jack Nicholson agreed to take the role. Michael Uslan had famously wanted Nicholson since he saw him back in the 1970s in films like 'One Flew Over the Cuckoo's Nest'.
Later, when Batman Forever was brought to the big screen they were looking at Robin Williams as what many at the time thought as a shoe-in role for the Riddler. Of course we know that Burton and Keaton left the project and when Schumacher came in he was looking at a new, hipper talent for the role..Jim Carey.
Robin Williams was public about wanting to be involved in the Dark Knight, and those that have seen him in his more serious and darker roles in the past decade could maybe see how he could bring a serious creepiness to a Joker role. Of course, Nolan went with Ledger, who also tragically passed. Robin Williams had told IGN this at the time:
“Well, you want to do a different Joker. You know, if they do Arkham Asylum, it would be amazing. Arkham Asylum is one of the greatest, nastiest comic books ever. It’s truly, it’s like the Marquee de Sade on that level, and wonderfully damaged and quite tragic, in terms of when you realize [what happened to] create these characters.”
Robin Williams gave it one more shot for the Dark Knight Rises when he spoke to Empire Magazine:
"Years ago they offered me The Joker and then gave it to Jack Nicholson, then they offered me The Riddler and gave it to Jim Carrey. I’d be like, “Okay, is this a real offer? If it is, then the answer’s yes. Don’t pump me again, motherfuckers.”
“I’m using this article as an ad. Chris, call me, I’ll do anything. I could be a great character — or some weird little man in the background in Arkham Asylum.”