/    Sign up×
Community /Pin to ProfileBookmark

Is there a javascript exit method that stops building the page? If I do a check at the beginning of my page, find something wrong, and want to only write an error the the screen, is there a call I can make to do so? Or do I have to put the rest of the page coding in a big else statement (serverside)?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@sovikFeb 07.2007 — a. Serverside script executes before javascript

b. I dont think there is any exit method except widnow.close

c. yes I think the only way is to use if .. else .. statement.
Copy linkTweet thisAlerts:
@toicontienFeb 07.2007 — What you could do is while the page is loading, activate a style sheet with styles that hide certain blocks of the page. And as the page loads, you could use JavaScript to set the display of those DIVs to 'block' if there isn't an error, or show the error DIV if there is an error.
[code=html]
<head>
<link rel="alternate stylesheet" media="screen" type="text/css" href="path/to/stylesheet.css" title="loading">
<script type="text/javascript">
// Enable the alternate "loading" style sheet
var loadingLINK = null;
if (document.getElementsByTagName) {
var els = document.getElementsByTagName('link');
for (var i=0, end=els.length; i<end; i++) {
if (els[i].title === 'loading') {
els[i].disabled = false;
loadingLINK = els[i];
}
}
}


function onSuccessfullLoad() {
if (loadingLINK) {
loadingLINK.disabled = true;
}
}


function onErrorLoad() {
if (document.getElementById) {
document.getElementById('errorDIV').style.display = 'block';
}
}
</script>
</head>
[/code]

As the page loads, it'll activate the alternate style sheet, which will contain the proper styles to hide the content you want hidden. Then the two functions will be executed at the proper times. If successful, the alternate style sheet is disabled again, revealing the content on your page. If not successful, the onErrorLoad function executes which displays the error message.
×

Success!

Help @vinays84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...