PDA

View Full Version : Null Error From "no flash content"


404notfound
12-17-2008, 02:01 PM
I am using swfobject javascript to write flash content to a div. while there are many great advantage to using this method one i rather like is how easy it is to display alternative content if the user does not have flash player installed. You simply put whatever you want to be displayed inside the div, if flash player is not installed it is displayed, if it is, the flash writes over the div content.

attributes.id = "flash";
swfobject.embedSWF("flash.swf", "flash",...

<div id="flash">no flash</div>

Since i'm using javascript to load the flash anyway, i took it a step further and used javascript to load the alternative flash content.


onload=function()
{
var txt=document.getElementById("noflash")
txt.innerHTML='<img src="bg.gif" width="400" height="250" alt="bg" title="">';
}

<div id="flash"> <div id="noflash"></div> </div>


The only problem is in ie, i receive a null error because when the flash is writen to the div the noflash div is "deleted" so when the javascript trys to write to it it doesent find it and i receive a null error.

One solution was to make a second hidden 'noflash' div but then i have a validation problem with duplicate ids.

rangana
12-18-2008, 12:40 AM
onload=function()
{
try{
var txt=document.getElementById("noflash")
txt.innerHTML='<img src="bg.gif" width="400" height="250" alt="bg" title="">';
}
catch(e)
{
// You can show the error by: alert(e.description)
// If you intend to keep IE/FF silent when error is received, don't place any code here
}
}

404notfound
12-18-2008, 02:39 PM
wow, thanks! that seemed to work... first time i've ever seen the 'try' code used. cool.