First of all, give thanks for reading my question and try to help me and apologize for my English.
My idea is create a library, function that from index.html returns a html.
For example, I call the function with: Video.generateIframe("1", controls, "video1") in index.html
"1" is the id of my video, controls are an array of options to show and "video1" is the id of the div.
My problem is that I dont know how return an html, well... when I execute the javascript returns next error:
Uncaught SyntaxError: Unexpected strict mode reserved word.
How can solve it?
var Video = (function () {
'use strict';
var publicAPIs= {};
// public method
publicAPIs.generateIframe = function(id, controls, target) {
let src = generateSrc(id, controls);
let iframe = '\n<div id=\'' + target + '\'>\n\t<iframe frameBorder="0" src=\'' + src + '\'>\n\t\t<p>Your browser not support iframes.</p>\n\t</iframe>\n</div>';
};
// private method
var generateSrc = function(id, controls) {
let urlServer = `http://example.com/panel?selectVideo=${id}`;
(controls.video) ? urlServer += '&video=1' : urlServer+= '&video=0';
(controls.stop) ? urlServer += '&stop=1' : urlServer+= '&stop=0';
(controls.fullscreen) ? urlServer += '&fullscreen=1' : urlServer+= '&fullscreen=0';
return urlServer;
};
return publicAPIs;
})();
EDIT:
Sorry, variable is publicAPIs... I generate a string with div container, now I think that I should append to other html component, a parent html component?
publicis reserved in strict mode. You call itpublicAPIslater anyway.return (<div id={target}>...This is known as JSX, popular with React. You will need a transpiler to be able to return this. You could return a string like @Madmadi mentions, or return a DOM node, that you prammatically created.