Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a local HTML file using window.open in Chrome

Tags:

javascript

I want to open a local HTML file through Javascript using:

window.open ("file://C:/Users/wins/Desktop/exclusiveWordpress.html","mywindow");

But it is opening a new window with a blank page as we used to get when URL is not specified. How do I achieve this?

like image 624
Viswa Avatar asked Feb 16 '11 01:02

Viswa


People also ask

How do I open an HTML file in a new window?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.

Why is my HTML file not opening in Chrome?

The file at file:///Users/.../index.html is not readable. It may have been removed, moved, or file permissions may be preventing access. Community content may not be verified or up-to-date.

How do I open a HTML file in my browser?

Open the saved HTML file in your favorite browser (double click on the file, or right-click - and choose "Open with").


2 Answers

This worked for me fine:

File 1:

    <html>
    <head></head>
    <body>
        <a href="#" onclick="window.open('file:///D:/Examples/file2.html'); return false">CLICK ME</a>
    </body>
    <footer></footer>
    </html>

File 2:

    <html>
        ...
    </html>

This method works regardless of whether or not the 2 files are in the same directory, BUT both files must be local.

For obvious security reasons, if File 1 is located on a remote server you absolutely cannot open a file on some client's host computer and trying to do so will open a blank target.

like image 172
DrewT Avatar answered Oct 21 '22 11:10

DrewT


window.location.href = 'file://///fileserver/upload/Old_Upload/05_06_2019/THRESHOLD/BBH/Look/chrs/Delia';

Nothing Worked for me.

like image 33
sapana Avatar answered Oct 21 '22 11:10

sapana