FAQ on CSBL: how it is possible to commuinicate among ExternalContent widgets
The CSBL os widget sender can be set as follow to present a button activating a trigger sending an event to another or to all:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
function ClickEvent(){ console.log("send");
parent.$('body').trigger('SendEvent', { suri : "MySuri" }); }
</script>
<body><button onclick="ClickEvent()"> send servicde uri </button></body></html>
A different External Content Widget with CSBL activated can receive the message via:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<html><body><div id="div1"> null </div> </body></html>
<script>
setDivText("div1", "valore da settare");
parent.$('body').on('SendEvent', function(event, data) {
setDivText("div1",data.suri);
});
function setDivText(divId, text) {
var div = document.getElementById(divId);
if (div) {
div.textContent = text; // mostra il testo all'interno del div HTML
} else {
console.error('Elemento con ID "' + divId + '" non trovato.');
}
}
</script>