1

I know this has been asked plenty of times, but this is a special case. I'm working on an online HTML editor, using the design function of HTML 5 browsers (yeah, I found a useful application for this feature). I want to let the developer load a page, but developers are lazy (so am I), so I don't want them to enter the full path to their page. To prevent this, I use a file input (id="temp") WHICH DOESN'T GO TO THE SERVER!!!

I tried to open the local HTML file in a new browser in several ways, but the relative links in the page don't work:

window.open(temp.files.item(0)?temp.files.item(0).getAsDataURL():'',title.value,'width='+screen.width+',height='+screen.height)

The URL is encoded. This way the links in the file don't work, like in a ZIP file.

last = window.open('',title.value,'width='+screen.width+',height='+screen.height)
if(temp.files.item(0))
last.document.body.innerHTML = temp.files.item(0).getAsText("utf-8")

This code opens a blank page and copies the HTML code to the blank page. Of course the links in this page don't work either. temp.value only shows the filename, not the path.

4
  • Your question is very unclear. What are you trying to do? You can't access the file system from JavaScript. Commented Apr 25, 2011 at 18:52
  • @coreyward well with some HTML5-related APIs you can, in some limited ways, but you still can't get path information. Commented Apr 25, 2011 at 19:00
  • input[type=file] can access the file system :) Commented Apr 26, 2011 at 13:52
  • I don't have to write to the file, I just have to open it in a new browser. The user can save it using the file->save option in almost every browser Commented Apr 26, 2011 at 14:22

1 Answer 1

2

Browsers simply will not tell you the information you want. The "value" property of "file" input elements does not contain the path.

If "the page" is really just an HTML page, then you might want to look into the HTML5 file reader stuff and see if you could at least read the file contents and dump them into a new browser window/tab. There might still be problems with HTML documents that expect to be able to locate auxiliary files (CSS, images, etc) via relative paths.

Sign up to request clarification or add additional context in comments.

1 Comment

You just restated my problem ):

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.