automatically alternate a div in a web page

It is quite easy automatically alternate a (image) banner in a webpage with javascript. But if you want alternate automatically a complex text it is not so easy.

First of all you have to know that is not possible use php, because the “duty” of php ends with the “production” of a page, and it is not usable to change something in a page alrealdy “made”.

Therefore, the only way is javascript. I found a js to change automatically images (every x time) and I modified it according to my needs.

il javascript

var slideIndex = 0;
showSlides();

function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slideIndex++; if (slideIndex > slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
// slides[slideIndex-1].style.display = "block";
// slides[slideIndex-1].className = slides[i].className.replace(" visible", "");
slides[slideIndex-1].style.display = "flex";
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 4000); // Change image every 4 seconds
}

l’html

Afterward I was able to use, within the html proposed a php code, as in the following

 $ads_verticale_dx="<code><p class=\"mySlides fade\"><span class=\"numbertext\">1 / 3</span><img src=\"someimage.jpg\" width=\"100px\" /><br />some <b>text</b> with<br /> <a rel=\"external\" href=\"somelink/\">some link</a></p>  
 <p class=\"mySlides fade\"><span class=\"numbertext\">2 / 3</span><img src=\"someotherimage.jpg\" width=\"100px\" /><br />some other <b>text</b> with a<br />  
 <a rel=\"external\" href=\"somelink/\">some other link</a></p>  
 <div style=\"text-align:center\"><span class=\"dot\"></span><span class=\"dot\"></span><span class=\"dot\"></span></div>  

il css

And this is the css to add

.mySlides {display: none; 
  }

/* Slideshow container */
.slideshow-container { vertical-align: middle; 
}

/* Caption text */
.text {
  display: none;
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  visibility: hidden;
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  top: 0;
}

/* The dots/bullets/indicators */
.dot {
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: none;
  transition: background-color 0.6s ease;
}

.active {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .text {font-size: 11px}
}

Last problem: how load the javascript. You can put it within the body, and this way it works without proiblems, but is a quite ugly solution. The best way is tu put the script within the head, or in a linked js file with all the other scripts, and then do (wihin the body tag) the command onLoad=”showSlides();”. But doing so, some browser, such as Chrome, could not understand the command. To fix this issue, be sure to use the correct case (onLoad, not onload) and try to delete the browser cache. This way you should force Chrome to recognize the script.

It works!

md linux viewer

Ci sono diversi editors, ma più raro è trovare visualizzatori (viewers) per linux di files md (markdown).
Dopo aver tentato una estensione di Firefox (https://superuser.com/questions/696361/how-to-get-the-markdown-viewer-addon-of-firefox-to-work-on-linux/1175837#1175837) che ha richiesto di modificare i mimetypes del sistema con esiti disastrosi, ho optato per una estensione di Chrome, MarkDown Viewer, che è andata a buon fine al primo colpo (mentre su Firefox avevo dovuto sudare sette camicie), non ha problemi di encoding e rende correttamente le immagini “ridimensionate” e “stilizzate”, ed è inoltre personalizzabile nella resa mediante il css (content.css): si veda il seguente file md

problema di visualizzazione di simboli

Si risolve dichiarando il font-family con uno span=class per esempio.

settare il browser per thunderbird

Può succedere che uno abbia impostato Firefox come browser predefinito, e ciò nonostante Thunderbird apra i suoi links con Chrome, ad esempio.
Allora bisogna andare in “Modifica -> Preferenze -> Avanzate -> Editor di configurazione” e modificare le due voci:

network.protocol-handler.warn-external.http
network.protocol-handler.warn-external.https

impostandole a “true”.
Successivamente, quando cliccherete sul link in una mail, Thunderbird vi  chiederà quale browser usare, e lì settate Firefox e dite di considerare definitiva questa scelta.
Così, da quel momento in poi aprirà sempre i links (http://) con Firefox. Ripetete la cosa per i links https:// e il gioco sarà fatto.

far vedere solo a Firefox certe proprietà css

Può essere utile far vedere solo a un certo browsers certi attributi css. Se il browser è Firefox la sintassi da usare, all’interno del file css è la seguente:
@-moz-document url-prefix() seguita da parentesi graffe che abbraccino tutta la porzione di css che si vuole nascondere agli altri browsers.

Chrome: prime impressioni

Ottima impressione: la velocità è notevole (sia in caricamento sia in navigazione). Ottimo il supporto agli standard W3C, in particolare ai css3.
Un po’ scheletrica l’interfaccia grafica, ma non si pu? avere tutto.