Powered by KikBooks Widget

By on June 2, 2007, with 31 Comments

Random Illusion Hack!You probably noticed a strange ribbon at the top of the page, in the left upper corner, that says “Random Illusion!”. Well, I think it is wonderful add-on for Mighty Optical Illusions. If you click that button, it will take you to one random illusion from our archives of over 1000 illusion articles.

What is so interesting about it, is that you never know what to expect! I couldn’t stop clicking it, and every time the page loaded, I was surprised seeing illusion I forgot I already posted :) I tried this so many times to see if some articles will re-appear twice, but I never managed. Go ahead, test it and if you get some articles re-appear twice, post in comments. I believe this add-on works in all web browsers. I tested it with Firefox and with Internet Explorer, but just in case I would appreciate if you commented your experience with different resolutions and different browsers. Also, I’m interested in your opinion, if the button is too intrusive. I believe all of you will adore it, but if for some reason many of you dislike this option, I shall remove it.

If you also use blogger platform for blogging, and want to implement “Random post” hack, you can do it easily by following these instructions (continued inside this article)…


1.) First, add the following javascript to your page’s header between head and /head tags. (Template -> Edit HTML):

<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://www.moillusions.com";

function randomPost() {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTotalPostsCallback&start-index=1&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};
function getTotalPostsCallback(json) {
var totalResults = json.feed.openSearch$totalResults.$t;
if (totalResults > 0) {
getRandomPostNumber(totalResults);
}
};
function getRandomPostNumber(totalResults) {
var randomNumber = Math.floor((Math.random() * totalResults) + 1);
getRandomUrl(randomNumber);
};
function getRandomUrl(randomNumber) {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTheUrlCallback&start-index=" + randomNumber + "&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};
function getTheUrlCallback(json) {
var theUrl = json.feed.entry[0].link[0].href;
window.location.href = theUrl;
}
//]]>
</script>

Make sure to replace the _yourBlogUrl variable with your blog’s URL, and just add the following link anywhere in your page:

<a href="javascript:randomPost();">View Random Post</a>

Since this uses JSON feed callbacks, you’ll need to make sure that you (at the very least) have summary feeds enabled for your blog. Many thanks goes to Janek37 for inspiring me to do this, and providing helpful tutorial.

Comments

31 Responses
  1. the person says:

    Awesome addition! You wondered whether it worked with all web browsers and I know it does work in Safari. I can’t stop clicking it!

  2. The Wolfgirl Liberation says:

    I love this site and visit it every day. I’d love to know how to add that random illusion ribbon onto my Myspace so people can click on it too,does anybody have any idea how???
    http://www.Myspace/thewolfgirlliberation

  3. Anonymous says:

    It works on Opera, just so you know – and I think it’s great; I’ve found lots entries which I’ve not seen before. And it’s also great ’cause some of us (including myself) are too lazy to wander through the different catergories ^^

  4. Luke says:

    Umm, Vurdlak, i clicked 5 times and ‘the devil is coming’ came up twice! When are you going to post my post!

  5. Chris says:

    i clicked on the ribbon 3 times and got the puzzled hunter twice in a row!

    btw, it works on safari

  6. Anonymous says:

    at one point the button just started giving me the same thing over and over again as if were hitting refresh. it doesnt work properly for firefox

  7. Ashok says:

    Does nobody care about the actual illusion here? :P

    Its so cool, I didn’t expect that and it took ages for me to find it…

  8. Anonymous says:

    Sweet illusion…(hint- look unfocused at the middle of the world).
    This took me about 3 min to find

  9. Anonymous says:

    #6 was wrong, i’ve got Firefox and it works perfectly

  10. kenia says:

    it works on MSN explorer! Oh, and that illusion to the left is awesome! with the woman and the globe!

  11. Anonymous says:

    Awesome illusion. At first I thought Australia was a nose in a cartoony face, but that’s not the illusion. Now I see the real illusion. Is everything geographically correct? It’s pretty cool.

  12. Anonymous says:

    so… i tried it in safari 2.0.4 and it worked prefectly, and i also tried it in (brace yourself for this one people) internet explorer 5.2.3. it didnt work in internet explorer cuz i didnt have the right plug-in, but… i dont think thats too big of a loss…

  13. Anonymous says:

    The line

    window.location.href = theUrl;

    would normally add a new entry to the browser history (as opposed to location.replace which would replace the current page with a new page). So, after clicking five times I’d expect to be able to go back five pages well. But somehow using the Ajax callbacks this does not work. In other words: it seems impossible to go back in the page history. Same behavior in Firefox, Safari and Camino on Mac OS X.

    Too bad the history doesn’t work, but a nice addition anyhow!

    Adrian.

  14. Anonymous says:

    Great illusion.. though i have to admit i had to look again to not see the face lol

  15. Anonymous says:

    the illusions like others…
    A hidden picture..

  16. King Smily says:

    Great addition! I have been hoping for something like this for a while! Now the trick will be getting me to stop clicking on it…

  17. Walt says:

    Excellent hack, thanks for sharing.

  18. Eddie says:

    WOAH!!! I got the same one twice!

  19. Anonymous says:

    I saw an illusion twice with he random illusions thing only.

  20. rzam0 says:

    i got this page twice with random illusion thingy

  21. Anonymous says:

    Has anyone notice that there already is a ‘Next Random Illusion’ button between the illusions and the comments section. That’s what I’ve been clicking since day one. When I want to look at something specific then I go to the sidebar. And it’s at a good spot, so that when you scroll down viewing the illusion there it be. And it’s right above the Add your comment button to boot.

    P.S. I love this site!

  22. Sytze says:

    Guess how i came to this page…
    With the random button!
    :-P

  23. Anonymous says:

    This one of my most favorite application on facebook.
    I don’t want to hurt your feelings but it only took me a few minutes to find the owl.
    Yes I do use the widget.

  24. Aish says:

    I use that upper “random illusion” button and the other one, too, and this same page came up twice! thats ok, though. The random buttons are great idea.

    I like the illusion. The map of the world seems abstract/distorted, especially where the lady’s face appears, but it is COOL visual effect! =D

  25. Genius says:

    I once got the same optical illusion randomly 3 times in a row, and another time twice o.O I’m always getting the same illusion over and over again. Not always in a row, but very often.

  26. anonymous someone says:

    tis is truely amazing! :)

  27. Special ED says:

    Whoa, that’s awesome.

  28. Annishia says:

    umm acually… i got to THIS post by the button!

  29. pokemon boy1 says:

    i got this 1 then scary illusion 4, then this again!!

Speak Your Mind

You can add some images too.

Pinterest