News for hackers. Stuff that matters.
Re:A file that's both an acceptable HTML page and a JPEG (vi... by achal on Friday July 06, 2012 @04:28PM (#4209499)
I've always wondered how the site snag.gy does something similar. Take this link, for example (you'll have to disable AdBlock if you want to see the ad): http://i.snag.gy/0obAy.jpg (ignore the image itself; it was one of the first to pop up in my history)

The source is just the image, and you can embed the image, but there's an ad under the image. Also, right click -> view image or copy image location point to the same URL.

Re:A file that's both an acceptable HTML page and a JPEG (vi... by lifeformed on Sunday July 08, 2012 @10:38PM (#4216429)
I made Snaggy! It's pretty hacky; each browser sends a slightly different header depending on if you're opening the image directly or if you're embedding it. I just have a check for each browser and serve the appropriate page. It doesn't work great on all browsers though (I haven't even tested mobile). I'm going to try to clean it up sometime.
Re:A file that's both an acceptable HTML page and a JPEG (vi... by achal on Monday July 09, 2012 @03:29AM (#4217106)
Hey, just wanted to say Snaggy is awesome. I saw your post a long time ago on Reddit, and you have saved me many seconds in the screenshot process. Not a huge fan of the fact that "View image" doesn't work exactly as I'd expect, but I understand the ads are necessary, so no complaints. Thanks for the awesome site!
Re:A file that's both an acceptable HTML page and a JPEG (vi... by gwillen on Friday July 06, 2012 @07:54PM (#4210151)
I suspect that's doing some kind of autodetection to decide which version of the page to serve. (Perhaps based on what MIME type the browser requests.)
Re:A file that's both an acceptable HTML page and a JPEG (vi... by 1880 on Saturday July 07, 2012 @07:19PM (#4213020)
Yep. In Chrome, pasting the URL in the address bar:

  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Embedding the URL as a <img> element in a HTML file:

  Accept:*/*
Re:A file that's both an acceptable HTML page and a JPEG (vi... by sohn8 on Saturday July 07, 2012 @02:06PM (#4212271)
Depends on the MIME type the server requests.

If your browser requests a html page, it will respond with a html page... and vice versa.