Hello,
I would like to add a widget to my site using some javascript code. I've added the code to the Public and made a help-widget.js. Here is the code:
(function(){ var w=window; function l(){ var d=document; var aws=d.createElement('script'); aws.type='text/javascript'; aws.async=true; aws.src='https://unity.wixanswers.com/apps/widget/v1/unity/------/en/embed.js'; aws.onload = aws.onreadystatechange = function() { var rs = this.readyState; if (rs && rs != 'complete' && rs != 'loaded') return; // try { // } catch (e) {} }; var s=d.getElementsByTagName('script')[0]; s.parentNode.insertBefore(aws,s); } if(w.addEventListener){ w.addEventListener('load',l); }else{ w.attachEvent('onload',l); } })()
How can I go about now adding this to the actual site?
code that does direct DOM manipulations is not "native" to the wix-code ecosystem.
hence, you do not place it in the standard code files for wix-code.
instead, you use the HTML component to essentially create an iframe, and place that code there.
you can then communicate with this component via messaging.
take a look here:
https://www.wix.com/code/reference/$w.HtmlComponent.html#postMessage
hope this helps.
Hello,
I am afraid I've tried attempting to add that to an HTML file yet it appears the widget isn't made to display that way.
Hi Jason,
Can you contact me please - i will be able to help you no problem with this.
robert@stevenbrownart.co.uk
Issue resolved :)