Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop page load in html static page

Is there in HTML (javascript) or other static html tech can:

  • Stop page loading (if browser does not download yet)
  • Stop page rendering (from where the code placed)
  • Stop javascript executed (from where the code placed)

Simply put, is there a code like

<script>window.StopWhateverBelow()</script> 

To let browser totally ignore whatever below the code.

UPDATE

I understand the browser may already download the whole thing. What I want is, from the code, page should stopped, for example: if I put the code just after <body> visitor should see blank page, if I put the code in middle of the page, page should be just half like you pressed ESC

ANSWER

As bukko suggested, comments done the trick. But not full, just half If you put <!-- in html page, the rest will be ignored. And in Javascript

document.write('<!--'); 

Done the trick.

For about make sense:

Here is how this code make sense: when you page load some offpage script, the script is dynamic. When the script code found something wrong (or match some condition), you have one more option to stop the page from rendering, loading, download...

like image 871
Eric Yin Avatar asked Jan 20 '12 14:01

Eric Yin


People also ask

How do I stop a page from loading in HTML?

Window stop() The stop() method stops window loading. The stop() method is the same as clicking stop in the browser.

How do I stop Dom from loading?

The stop() method in DOM is used to stop the window from loading resources in the current browsing context, similar to the browser's stop button. Example: Stop window from loading.

How do you stop a page in Javascript?

The window. stop() stops further resource loading in the current browsing context, equivalent to the stop button in the browser. Because of how scripts are executed, this method cannot interrupt its parent document's loading, but it will stop its images, new windows, and other still-loading objects.


2 Answers

You could do window.stop(); for most browsers besides Internet Explorer. For IE, I had to use document.execCommand('Stop');

like image 182
cyberboxster Avatar answered Sep 26 '22 00:09

cyberboxster


If you already have html comments on your page, @bukko's solution doesn't fully work. Stuff after the html comment will get rendered normally.

Something else to try is:

document.write('<script type="text/undefined">') 

The rest of the document gets interpreted as part of the script tag, and because the script isn't text/javascript, it gets ignored.

Worked for me, thought I'd share it.


Edit

I've seen the script trick not work in Chrome.

This does work, but I have not done extensive browser testing:

document.write('<style type="text/undefined">') 
like image 32
chowey Avatar answered Sep 25 '22 00:09

chowey