On Jun 17, 2:52 pm, "Scottus " <[EMAIL PROTECTED]> wrote: > I am using > > var title = document.getElementsByTagName('title').item(0).innerHTML; > > to get the content of a pages title tag. > > But if the page has no title tag I get > > "Error: document.getElementsByTagName("title").item(0) has no properties" > > and the script craps out. > > any ideas about how to deal with this ?
An HTML document without a title element is invalid. Christopher has given you a jQuery answer, a generic answer is that if you try to get a property of an object that doesn't exist your script will error. If you want a belt & braces approach, try something like: var o; if ( document && document.getElementsByTagName && (o = document.getElementsByTagName('title')[0]) && (typeof o.text == 'string') ) { alert('The document title is: ' + o.title); } Or if you like being a little more risque, try: alert( document.title ); -- Rob