Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop.

Restrictions:

No looping or control structures of javascript and jQuery allowed. You can only use alert, events, etc.

share|improve this question
1. What's the winning condition? 2. What does it mean for a page to be in an infinite loop? – Peter Taylor Oct 3 '12 at 8:37
ok, Just edited the question including winning condition. – Darshan Thanki Oct 3 '12 at 8:42
@grc: I'm not so sure it's ambiguous; a blank page doesn't require that the browser must be closed to continue. However, I don't think it's possible to do this in modern browsers. I'm not on Windows, but I can remember how to crash IE without using loops (though that may have been fixed in IE 9/10). – Andy E Oct 3 '12 at 9:21
@Andy E: I don't really get what you mean by continue. Does it mean that you are able to use elements on the page, or that you are able to use other pages in the browser? – grc Oct 3 '12 at 9:32
@grc: the OP makes it sound like he wants to lock up the browser and force it to be closed. This is difficult/impossible in browsers with sandboxed tabs, but you can crash a tab (see Florian's example). – Andy E Oct 3 '12 at 9:51
show 4 more comments

4 Answers

up vote 6 down vote accepted
$($);

May not meet your conditions, but I like it. (And it does crash your browser.)

More information about this: Why does $($) crash my page?

share|improve this answer
Yup, this locks up my tab in Chromium. – Andy E Oct 3 '12 at 9:51
I see what you did there florian – Abhishek Oct 3 '12 at 12:18
@AndyE that locks up all browsers i have Safari , Opera , Chrome , Firefox , Aurora , Canary , RockMeIT , Maxathon ...... All hail jQuery .. they should put this as feature.!! Creates cross browser crashes :D – Abhishek Oct 3 '12 at 12:19
Little but awesome solution. I just thought of this one for the first time I came up with this question. Bravo, @florin – Darshan Thanki Oct 3 '12 at 12:55

How about a meta refresh?

<meta http-equiv=refresh content=1>

I removed the quotation marks around the parameter values because code golf.

share|improve this answer

This reloads the page as soon as it loads:

<html>
<head>
<script>window.location=window.location</script>
</head>
</html>

Or you could bring up infinite alert boxes (until the user disables them):

<html>
<body onfocus="alert('')"></body>
</html>
share|improve this answer
5 years ago I would have voted on this. However, most modern browsers have a checkbox on the alert that will prevent further dialogs from appearing. – Andy E Oct 3 '12 at 8:47
That's right. Even if you don't check it, the browser limits alerts to a specific number. Here is Google security policy that explains more about it. – Darshan Thanki Oct 3 '12 at 8:50

This will reload the browser indefinitely:

location.reload()

(Unless the browser specifically blocks repeated reloads.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.