Responsive JS inside template

dbembibre

Active member
I need to load a external js file only in web mode.
I did this inside a new template, is working fine, but i dont know if is the good way.

Code:
<script>
    width = document.documentElement.clientWidth;
    if (width > 750)
    {
            <xen:if is="!{xen:helper ismemberof, $visitor, 19,4,3,5,20,25}">
                var script = document.createElement('script');
                script.type = 'text/javascript';
                script.src = 'http://web.com/show.jsp?id=624449&cor=002E0';
                document.getElementsByTagName('head')[0].appendChild(script); 
            </xen:if>
    }
</script>
 
That should work but you can replace your script insert part with a single line like this

Code:
<script>
    width = document.documentElement.clientWidth;
    if (width > 750)
    {
            <xen:if is="!{xen:helper ismemberof, $visitor, 19,4,3,5,20,25}">
                  XenForo.loadJs('http://web.com/show.jsp?id=624449&cor=002E0');
            </xen:if>
    }
</script>
 
Back
Top Bottom