Monday 22 October 2018

Browser size - Javascript

Sometimes when you are building a web page it is useful to know what the browser size is, so you check it will display correctly if it is on a desk top, lap top, tablet or mobile.

The following Javascript will put the browser client size as the title.
<html>
<head>
    <script>
        function titleIsSize() {
            document.title = "" + document.body.clientWidth + " pixels.";           
        }
    </script>
</head>
<body  onresize="titleIsSize()"  >
</body>
</html>

Monday 15 October 2018

Raspberry Pi sound not working on HDMI

By default the Raspberry Pi will channel sound through the HDMI connection to a suitable television/monitor.

Most of the time that will work automatically (if it thinks the television/monitor is not equipped with a speaker or speakers, it routes it through the headphone socket).

The key thing is the "sometime".

Some television/monitors do not appear to tell the Raspberry Pi they have a speaker. This may be due to the monitor, or due to the HDMI cable in use.

The easiest way of forcing the sound to be output via one of the channels is to right click on the loudspeaker icon. The drop down will show available audio output devices, the tick indicating the selected one. Make your choice there.

You can also use the command line:
amixer cset numid=3 2

The parameter 2 sets output to HDMI, 1 sets it to the headphone socket and 0 sets it to default.

It is also possible using the configuration screen and by editing the /boot/config.txt file. See the reference for details.

References:
https://www.raspberrypi.org/documentation/configuration/audio-config.md