-1

I created a project with an index.html file in my root folder with Brackets. Because there are common js/css files significantly I wanted to create projects under this root to be able to reach these common files from my current root. So I gave ../../ before my all paths for each of the links and scripts for my subfolder's index.html like below,

<script src="../../js/main.js" type="text/javascript"></script>

But soon I realized it made my javascript functions fail even if it's obviously working otherwise. I couldn't figure out why and I'll appreciate any idea about it.

debugger

Erhan Yaşar
  • 847
  • 1
  • 9
  • 25
  • Maybe it's better to add the body of `window.onload` in `main.js` (where that function is used). It is possible that the problem isn't really that path issue you're speaking of. – KarelG Mar 07 '17 at 07:37
  • You'll get this error when the element you're trying to add the listener doesn't exist. Are you sure they exist? – arc Mar 07 '17 at 07:38
  • It works if I copy the components and made paths correctly. This problem occurs if I change the paths and carry the folders @arcs. And my `main.js` is consist of a just `window.onload` function in it with some other event listeners in itself @KarelG – Erhan Yaşar Mar 07 '17 at 07:44
  • @ErhanYaşar I guess we would need to see some code, as the scripts are included ( we don't see any 404 messages ) the problem has to be in the code, would you mind sharing the crucial parts? – arc Mar 07 '17 at 08:02
  • I edited the question, you may see all the code on codepen. The thing is it doesn't fail if paths and the folders are included in the same folder @arcs. – Erhan Yaşar Mar 07 '17 at 08:21
  • You need to provide a [mcve] in the question itself. Don't provide "all the code": that isn't minimal. Don't put the code only on codepen: that isn't in the question itself. – Quentin Mar 07 '17 at 08:55
  • Your #fileInput doesn't exist. Do you create it with code or is it hardcoded in your html? When you run your webserver, do you cd into each folder every time? If you run your webserver inside the index.html folder I think he can't access the ../../ folder because it's behind its root. – Jonas Grumann Mar 07 '17 at 09:18
  • tx @Quentin, I edited the question as just showing the code itself instead of `codePen` and it's the best way to show the struggle I guess. And `#fileInput` exist on either `html` and `main.js` if you check again @Jonas Giuro. I don't run any `web server` by myself but it's **brackets** itself and probably this is causing to not to reach the `root` I showed. – Erhan Yaşar Mar 07 '17 at 10:51
  • @ErhanYaşar — Code should be expressed in the form of text, not in the form of a blurry picture. You still need to provide a real [mcve] and not a small sampling of HTML that might be related to the problem. – Quentin Mar 07 '17 at 10:53
  • I re-edited @Quentin – Erhan Yaşar Mar 07 '17 at 10:58
  • You still need to provide a real [mcve]. A few random script elements are not enough to reproduce the problem. You need to include the JS and the HTML it operates on. And not *all* the JS and HTML. Hence "minimal". – Quentin Mar 07 '17 at 11:15
  • You may edit the question yourself if you have priority or describe more precisely to reorganize as you gained more experience to make me to do so. I tried my best to display the whole index.html & main.js to make it more understandable @Quentin. – Erhan Yaşar Mar 07 '17 at 11:26
  • @arcs I just can figure out the issue and realized how it looks like (terrible). I re-edited both the question and the answer that I think looks better and wanted to thanks anyway warning me. – Erhan Yaşar Mar 15 '17 at 11:59

1 Answers1

0

After @Jonas Giuro's answer I tried it with node's http-server instead of live preview of brackets and it doesn't fail. The issue #6714 is probably the main cause to not being able to access behind its root directory. There is mainly two alternatively same methods I could think of;

  • For brackets users, simply starting live preview (with command + alt + P) at the top root folder and then switching in the subfolders (any html or anything) works flawless.

  • And for the ones using http-server via terminal with npm are able to host the top root folder again to be able to serve the subfolders as wishes.

Erhan Yaşar
  • 847
  • 1
  • 9
  • 25