Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script tags #14

Closed
timoxley opened this issue Nov 17, 2012 · 10 comments
Closed

script tags #14

timoxley opened this issue Nov 17, 2012 · 10 comments

Comments

@timoxley
Copy link
Contributor

Not exactly sure what the issue is (no time to debug ATM), but discovered a script element created by domify doesn't load its src when its added to the dom, unlike a script tag added via document.createElement('script').

@tj
Copy link
Contributor

tj commented Nov 17, 2012

yeah browsers wont execute them via innerHTML, I can't recall why, some legacy / security issue probably. jQuery does that portion for you

@timoxley
Copy link
Contributor Author

Reckon it's worth adding? Perhaps as a separate component?

@tj
Copy link
Contributor

tj commented Nov 17, 2012

it's definitely subjective, might as well be a separate component I think, later we can use that new one thought domify as an option if it makes sense

@jonathanong
Copy link
Contributor

looks like in IE, you have to set the defer attribute: http://msdn.microsoft.com/en-us/library/ie/ms533897(v=vs.85).aspx

closing for now.

@lancejpollard
Copy link
Contributor

running into this right now. basically we are loading a script from microsoft which itself overrides document.write, and they "write" a bunch of script tags all over the place.

https://gist.github.com/lancejpollard/a6f9309f47e3bda874af#file-microsoft-md

they give you a way to set a function so you can avoid overriding document.write, which is okay. so what i was doing was this:

window.mstag._write = function(str){
  document.body.appendChild(domify(str));
};

that would be cool because if microsoft were to ever change their internal implementation to include more than just script tags, it wouldn't break. currently, they pass both <script src="x"> and <script>some code</script>. what do you think about the appropriate way to implement this? is it at the domify level? seems like it should be, b/c you're expecting that you can create dom nodes the same way as if document.createElement (at least i was).

if not, you'd pretty much have to always do something like this if you wanted it to be robust:

document.body.appendChild(scriptify(domify(src));

thoughts?

@mainiak
Copy link

mainiak commented Jul 8, 2014

I run into this as well. Bet when I was searching for solution I found this - http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml - and isn't nice at all :-/

@lancejpollard
Copy link
Contributor

/cc @jonathanong can we add something like this to it?

@jonathanong
Copy link
Contributor

remove all the script tags after domifying the html, remove them all, append the child, then eval them. not sure what else to do.

but i have no idea what to do with document.write()s

@lancejpollard
Copy link
Contributor

@jonathanong the document.write is a separate issue it turns out. the main thing is you can't create <script> tags as you would expect to. what should be done is basically this:

var el = domify(str);
if ('script' == el.tagName.toLowerCase() && el.getAttribute('src')) {
  var tmp = document.createElement('script');
  tmp.src = el.getAttribute('src'); 
  tmp.async = true;
  el = tmp;
}

but for each script tag we should do that. can we include that in this library? otherwise domify doesn't work as you'd expect.

maybe it should go somewhere else?

@jonathanong
Copy link
Contributor

yeah i don't mind. should be a separate method that pulls the scripts and rejiggers them. something like:

var el = domify(str);
var scripts = domify.scripts(el);

then el would probably be empty if all it was was a <script> tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants