In this shot, we will learn how to stop browser window to load html page using window.stop()
.
Today’s websites contain images, graphics, JavaScript, and media, which makes a website heavy, and thus results in late loading of content on the website.
You can stop the content loading if it takes more time to load.
window.stop()
methodwindow.stop()
will stop the loading of a web page in a browser window after it is called, and it does not return any value.
The browser stop button is a working example of window.stop()
.
We use the window.stop()
method when some images, media, graphics takes time to load on a web page. By doing this, our web page will run faster than normal.
We are creating a web page with text content, so we will use window.stop()
to stop loading the HTML content after it is called.
This is only to explain how window.stop()
works. In reality it has different implementations, but here we are directly using it.
In the HTML code example above:
Line 3 has a script tag with JavaScript code.
In line 5, we called window.stop()
, which will stop the HTML page to load.
In line 13, we have the <p>
tag, which has the text ‘Hello, welcome’ that should display on the web page.
As we can see, the browser does not load the HTML page in the browser window because of the window method window.stop()
.
If you remove or comment line 5, the HTML page will work normally and will display the text in the window.
Most browsers support this functionality, but some browsers, like Internet Explorer, do not support
window.stop()
.