/Ugly/ + 'JavaScript'

A place for ugly, silly, or just-plain-crap JavaScript.

Hating the back button, and exception abuse

Saw these snippets on the site of a company that provides “industry leading solutions”. Firstly a snippet that was in the <head> of every page, intentionally breaking the back button:

<script>window.history.forward(1);</script>

And there was also this function which abuses exceptions for control flow (I’m not too sure why):

function crossFrameScripting()
{
	// TT#157678 - Prevent Frame usage. (esamson)
	//if (AgentUtils.isIE)
	//{
		try
		{	
			if(self.document.domain.toString() != top.document.domain.toString())
			{
				throw "Access is denied";
			}
		}
		catch(exc) 
		{
			if (top != self)
			{
				top.location=self.location;
			}
		}
	//}
	// /TT#157678 - Prevent Frame usage. (esamson)
}
Posted by Daniel15 on 22 Oct 2011 | linky

Subscribe or follow @UglyJS!
.........
Fork then send a pull request to contribute.