0

I followed a tutorial made by Jerry Hildenbrand, where he teaches how to control a LED via local network.

His tutorial works perfectly, I just need to type tightvncserver in the raspberry and open any browser (even in the mobile) with the raspberry pi ID address and everything works perfectly.

The problem is if I try to open the

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="viewport" content = "height = device-height, width = device-width, user-scalable = yes" /> 
        <title>Pi-lights</title>
        <script type="text/javascript" src="/webiopi.js"></script>
        <script type="text/javascript" src="/js/superled.js"></script>
        <link rel="stylesheet" type="text/css" href="/css/superled.css">
        <link rel="shortcut icon" sizes="10x10" href="/img/LED-icon.png" />
</head>
<body>
        </br>
        </br>
        <div id="content" align="center"></div>
        </br>
        </br>
        </br>
        <p align="center">Push button; turn the led on</p>
        </br>
        </br>
</body>
</html>

The button created in javascript doesn't appear in my browser(like in the browser on right side), even though I can make the background color appear just changing the CSS path (removing the slash)

from

<href="/css/superled.css">

to

<href="css/superled.css">

I don't know why, all the folders and files follow the same structures that is inside the raspberry pi).

enter image description here

enter image description here

  • Have you tried doing the same (removing the leading slash) with the 2 javascript paths? – Steve Robillard Aug 3 '17 at 14:14
  • Yes, I did. still not appearing. – Thiago Farias Aug 3 '17 at 14:16
  • When I am using the raspberry IP address the page is normal, just when I open the index.html there is the problem. – Thiago Farias Aug 3 '17 at 14:23
  • XY problem: why are you trying to locally open the index.html file if requesting it from the RPi's web server works? – Hydraxan14 Aug 3 '17 at 15:19
  • Because it is easier and faster for edit and test any new alteration a make in the code. Also I am new using html, javascript and raspberry pi, so I am not sure what is the best way to program. Thank you . – Thiago Farias Aug 3 '17 at 15:45
0

when you open your website from web server http://192.168.0.38:8000 all resources images or js files are relative or absolute to the root web site folder for example <href="/css/superled.css"> mean for the browser the file located in : /Users/.../myhomefolder/mywebsitefolder/css/superled.css, but when you open the file from file system File://Users/.../index.html resources are relative to the root system folder which mean the browser will search file in the current path : /css/superled.css which for sure is not correct. instead opening file from File system open the web server page.

  • Exactly the answer I was expecting. Thank you very much. You very good. – Thiago Farias Aug 3 '17 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.