Creating a script inside javascript

Hi experts, a new guy, and I have a program that creates a dynamic script inside an existing script

<html>
<head>
    <title>Depot</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
    function hideURLbar(){ window.scrollTo(0,1); } </script>
    <link href="localfiles/css/pignose.layerslider.css" rel="stylesheet" type="text/css" media="all" />
    <link href="localfiles/css/style.css" rel="stylesheet" type="text/css" media="all" />
    <script type="text/javascript" src="localfiles/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="localfiles/js/pagebuilder.js"></script>
</head>
<body onload="BuildHome()">
    <div id="header_content"></div>
</body>

 function BuildHome(){
var bannergrid = document.createElement("div");
    bannergrid.className = "banner-grid";
var visual = document.createElement("div");
   visual.id = "visual";
ba nnergrid.appendChild(visual);
var slide_visual = document.createElement("div");
    slide_visual.className = "slide-visual";
visual.appendChild(slide_visual);
var banner_ul = document.createElement("ul");
    banner_ul.className = "slide-group";
slide_visual.appendChild(banner_ul);    
var slide_script_pignose = document.createElement("script");
    slide_script_pignose.src="localfiles/js/pignose.layerslider.js";
    slide_script_pignose.type="text/javascript";
var slide_script = document.createElement("script");
    slide_script.type="text/javascript"; 
var slide_script_text = document.createTextNode("$(window).load(function() { $('#visual').pignoseLayerSlider({ play    : '.btn-play', pause   : '.btn-pause', next    : '.btn-next', prev    : '.btn-prev' }); });");
    slide_script.appendChild(slide_script_text);
bannergrid.appendChild(slide_script_pignose);
bannergrid.appendChild(slide_script); 
banner_ul.appendChild(slide_li);
document.getElementById("header_content").appendChild(bannergrid);}

when it starts, an error is not displayed, but the added script does not dynamically work, for example: FIY: this is a slider image

<div id="visual">

was created dynamically and must have a class that is also dynamically added from

pignose.layerslider.js

and it should be like this:

<div id="visual" class="pignose-layer">

but it does not display the class. I need to dynamically add a class inside pignose.layerslider.js because of its functionality. My analysis is that a script that was added dynamically is not working / not running please help if this is a way to run / execute a script that was added inside a script or something that can help!

! :)

+4
2

, jQuery?

<meta>:

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

. fooobar.com/questions/34141/...

, , script .

+1

. . , .

script. script onload script.

var headEL = document.getElementsByTagName('head')[0];
var scriptEL = document.createElement('script');
scriptEL.type = 'text/javascript';

scriptEL.src = 'https://rawgit.com/adikari/07690f28bcbe751d0694215d83cff30f/raw/4f045b95c7b3971ef0c7bf917ef9362635cea200/hello.js';

scriptEL.onload = function() {
    sayHelloFromExternalScript();
};

headEL.appendChild(scriptEL);
Hide result
+1

Source: https://habr.com/ru/post/1693808/


All Articles