The answer you mentioned uses Window.open(). From MDN:
The Window interface's open() method loads the specified resource into
the browsing context (window or tab) with the specified name. If the
name doesn't exist, then a new window is opened and the specified
resource is loaded into its browsing context.
Syntax
var window = window.open(url, windowName, [windowFeatures]);
Parameters
url
A DOMString indicating the URL of the resource to be loaded. This can
be a path or URL to an HTML page, image file, or any other resource
which is supported by the browser. If the empty string ("") is
specified as url, a blank page is opened into the targeted browsing
context.
windowName
A DOMString specifying the name of the browsing context (window or
tab) into which to load the specified resource; if the name doesn't
indicate an existing context, a new window is created and is given the
name specified by windowName. This name can then be used as the target
of links and forms by specifying it as the target attribute of or
elements. The name should not contain whitespace. Keep in mind
that this will not be used as the window's displayed title.
_comments
is just a random name that's supposed to be not used so that it's opened in a new window. You can't use that function. To open in the same window/tab you'd need to use something else, for example Window.location
The Window.location read-only property returns a Location object with
information about the current location of the document.
Though Window.location is a read-only Location object, you can also
assign a DOMString to it. This means that you can work with location
as if it were a string in most cases:
location = 'http://www.example.com'
is a synonym of
location.href = 'http://www.example.com'
Example #1: Navigate to a new page
Whenever a new value is assigned to
the location object, a document will be loaded using the URL as if
location.assign() had been called with the modified URL. Note that
security settings, like CORS, may prevent this to effectively happen.
location.assign("http://www.mozilla.org"); // or
location = "http://www.mozilla.org";
However, once you load a .txt file, your JavaScript is gone. So loading a plain .txt file in the browser is probably not the best idea. If you're using jQuery, consider creating a <div id="textfile">
. You can place the text file contents inside it by doing:
$("#textfile").load("file.txt", function() {
// do your scrolling here
});
In terms of scrolling through it, in plain JS it's tricky. If you're using jQuery, there's jquery.scrollTo. You'll be able to use any of the following in your function then:
$.scrollTo("250px");
$.scrollTo("50%");
$.scrollTo("+=25px");
$.scrollTo("max");