Re: [w3c/webcomponents] Make JavaScript Files a Valid Entry Point to a Web Page (#807)

Currently, you can use client-side javascript to modify an "already existing" html document.

You can even create an html document from scratch using client-side javascript as long as you import it into an iframe:
https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument

What you can't do, is this:

```
function makeDocument()
{
         
  var doc = document.implementation.createHTMLDocument("Document Generated By Client-Side Javascript");
  doc.documentElement.lang = "en";
  var meta = doc.createElement('meta');
  meta.setAtribute("charset", "UTF-8");
  doc.head.appendChild(meta);
  
  var p = doc.createElement("p");
  p.innerHTML = "This is a clickable paragraph.";
  p.addEventListener('click', function(event){ alert("Yes, this click event should work!") });
  doc.body.appendChild(p);
  return doc
}
export let clientSideDynamicallyGeneratedDocument = makeDocument();
```

If you navigate to a javascript file, like the one above, the browser will simply show you the source code; it won't run the file.

I believe, that if a client-side javascript module is directly navigated to, and exports a valid html document, the browser should run that javascript and display that document instead of just showing the source code.

It is an unnecessary limitation that javascript must be encapsulated by (or called from) an HTML document to run, and the consequence of that unnecessary limitation, is that I'm constantly making ridiculous html files that look like this:
```
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Temparary: Soon To Be Modified by Javascript</title>
</head>
<body>
 Temparary: This content will be completely replaced by javascript.
 Have a nice day!
</body>
</html>

```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/807#issuecomment-487782522

Received on Monday, 29 April 2019 23:52:23 UTC