/    Sign up×
Community /Pin to ProfileBookmark

I know that I can test if a browser can use a particular DOM command by:

[code=php]
if (document.getElementById() == false) { alert(‘Browser NOT compatible with program’); }
[/code]

My question is this: Where do I put this? First line of script? In an ‘onLoad=’ function? Somewhere else?

Second question: Is there a similar check to see if an AJAX file load can be used for a particular browser?
Again, where do I put it? (I know, this is a loaded question! ? )

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@mrhooNov 30.2007 — document.getElementById() will throw an error.

use if(document.getElementById) to see if it is supported.

Put it before you need to use the method.
Copy linkTweet thisAlerts:
@FangNov 30.2007 — Put it before you need to use the method.[/QUOTE]
Before you load the script
<script type="text/javascript">
if(document.getElementById) {
document.write('<script src="generic.js" type="text/javascript"></script>');
}
</script>
</body>
http://developer.yahoo.com/performance/rules.html#js_bottom
Copy linkTweet thisAlerts:
@JMRKERauthorNov 30.2007 — Thanks 'mrhoo' and 'Fang'. I appreciate the information.

Third question:


Is there a more acceptable way to stop a script from acting when a DOM command is not supported?

Is there an 'abort("message")' command?

OR is

if (document.getElementById) { // continue with script

} else { alert('Browser NOT supported'); } // exit script!

more acceptable?
Copy linkTweet thisAlerts:
@KorNov 30.2007 — Use [B]return[/B] command when the condition is not fulfilled (the [COLOR="Blue"]![/COLOR] operator, which is somehow equal with: "is not"). That will stop the code.
<i>
</i>if(!document.getElementById){
return
}
else{
...
}
Copy linkTweet thisAlerts:
@JMRKERauthorNov 30.2007 — Thank you 'Kor'.
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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