Jump to content

W3.JS and using w3-include-html


pgscweb

Recommended Posts

I use w3-include-html  to bring in certain portions of a website. I noticed on our footer page that has javascript within the html snippet does not work. Is there a way to get it to work using this library? Is there a work around?

Thanks in advance!

Link to comment
Share on other sites

The JavaScript has to be run from the page it included in, by using callback https://www.w3schools.com/w3js/w3js_include.asp

For example

<div w3-include-html="Footer.html"></div>
        <script>

            function dothis() {
                x = document.getElementById("test");
                if (x) {
                    alert(x.nodeName);
                }
            }

            w3IncludeHTML(dothis);
        </script>

Footer.html

<h1 id="test">Hello from footer</h1>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...