Question

I have a site that is accessed by raspberry pis and everything else. I need to display a keypad when the a PI access the site and not when everything else access is. I figured i would run a simple platform check as a PI returns Linux armv6l and everything else will return Win32. But i can not get a simple test of the logic to work.

my Javascript browswer.js in static/js

function myFunction(){
if( /Linux armv6l|Linux armv7l/i.test(navigator.platform) ) {
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
}
else    {
txt= "<p>Browser Language: " + navigator.language + "</p>";
}
document.getElementById("example").innerHTML=txt;
}

my HTML

<html>
    <head>
    <title>test</title>
    </head>
<body>

<h1>Welcome</h1>

<p id="example"></p>



</body>
<script type="text/javascript" src="static/js/browser.js"></script>
</html>

I am very new to Javascript and HTML so i am sure i am doing a few things wrong but i cannot figure it out. thanks

Was it helpful?

Solution

function systemdetect()
{
systemname=navigator.platform;

if (systemname.indexOf("Linux armv6l")!=-1) {
    systemname="pi"
    document.write("<p>this is a test.</P>")
    }

else {if (systemname.indexOf("Win32")!=-1) {
    systemname="MS 32"
    document.write("<p>this is a Win32 tes.</P>")   

}

else {systemname="N/A"}};

}

is what i ended up using to test for PI

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top