Script in separate template
Rork last edited by Rork
I have a template as an external HTML file, containing a <script>.
The script is executed in Chrome but not in Firefox. Is it a bug?
@Rork I think there is a bug in Firefox itself that doesn’t allow running this script. I’d recommend using lifecycle events if you need to support Firefox for PWA or anything like that. The hooks are fine for hybrid apps since you only need to worry about Safari and Chrome (which are the supported browsers in Onsen UI). I’ll add a note about this in the guide :+1:
Too bad… Putting the script in the relevant file would be better for the app design (encapsulation). If you know the Firefox bug reference, I’m interested.
@Rork I couldn’t find information about this issue on Firefox but I think the following code doesn’t work on Firefox:
var doc = document.implementation.createHTMLDocument(); doc.write('<div id="test"></div>'); doc.close(); doc.getElementById('test');
In Chrome and Safari this code returns the element correctly but Firefox doesn’t create it and returns
null. This is used to create
<template>that come from separate files :/
Chrome also works properly with
document.importNode(unlike Safari and Firefox).
Unfortunately, I think there’s not too much information about implementation details of this stuff, only the specs.
Try to replace
doc.documentElement.innerHTML = '<div id="test"></div>';
@Rork Well, even if that works, by specs
scripttags created with
innerHTMLwon’t be executed so it’s not possible to use that.
However, I just gave it another try and I came up with a work around that works in Firefox. I’ll test it a bit more :)
OK thanks :-)
This is working now :+1: Thanks for your great work and nice library!