News for hackers. Stuff that matters.
Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by chewxy on Thursday June 05, 2014 @02:36AM (#7850526)
Reminds me of an example I gave in my book about how you can write valid HTML that executes as JS:

    /*
    <div id="writeHere"></div>
    <script src="#"></script>
    <div>For example here, we have multiple examples of code that execute</div>
    <!--
        */
        writeHere.innerHTML='<p style="font-weight:bolder">Hello World</p>'
        alert("are we JavaScript files or are we HTML?")
        /*
    -->
    */
I saw this once upon a time while debugging some nasty code some publishers used - the whole site was in this style. It was one of the most ingenious things I've seen - the same file, parsed twice, once as HTML and once as JS.
Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by MasterScrat on Thursday June 05, 2014 @05:53AM (#7851087)
I fail to see why anyone would use that instead of inline <script> tags?

Is it because each tag would then be parsed and run in order, ie you couldn't declare a function at the end of the page that you'd use at the top? It's the only explanation that comes to mind...

Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by chewxy on Thursday June 05, 2014 @09:32AM (#7851835)
IIRC I was investigating a click fraud or impression fraud issue and I came across an entire site written in this fashion.

They were doing something funky with the ad tags that loaded on the page. Clearly they think it will deter people from discovering their naughty misdeeds

Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by aidos on Thursday June 05, 2014 @03:46AM (#7850723)
You'll end up with the leading '/*' (and trailing) showing in the html though. Not much you can do about it I guess (except probably use a css hack to hide it).

ps I don't envy anybody who has to spend their day working on code that looks like that!

Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by kristopolous on Thursday June 05, 2014 @02:39AM (#7850531)
Wow is that ever clever!
Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by dmak on Thursday June 05, 2014 @03:49AM (#7850730)
This is interesting, could you explain this more in detail?
Re:Show HN: TopLevel – A New Way to JavaScript Your HTML by Kiro on Thursday June 05, 2014 @05:13AM (#7850985)
Not OP but:

1. Page is parsed as HTML, ignoring the JS since it's wrapped in HTML comments.

2. script src="#" loads itself.

3. Page is parsed as JS, ignoring the HTML since it's wrapped in JS comments.