PDA

View Full Version : Updating the contents of a table cell


Yardgnome
09-07-2004, 05:02 AM
I was curious if it was possible to change the contents of a cell. For instance when ever the user clicks on a link, instead of loading a a whole new page, it will load, specifically, a new .swf in a certain table cell that is specified. Is this even possible without using frames? Thanks,

The YardGnome

hemebond
09-07-2004, 06:11 AM
Yes. See the Gecko DOM Reference (http://www.mozilla.org/docs/dom/domref/) for more details.

glenngv
09-07-2004, 06:13 AM
Try this:


function insertFlash(targetId, swfFile, w, h){

var flashTag = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ' +
'width="' + w + '" height="' + h + '">' +
'<param name="movie" value="' + swfFile + '">' +
'<param name="quality" value="high">' +
'<embed src="' + swfFile + '" quality="high" ' +
'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ' +
'type="application/x-shockwave-flash" ' +
'width="' + w + '" height="' + h + '">' +
'</embed></object>';

document.getElementById(targetId).innerHTML = flashTag;
return false;
}
...
<a href="sample.swf" onclick="return insertFlash('flash', this.href, 150, 150)">Link 1</a>
<a href="sample2.swf" onclick="return insertFlash('flash', this.href, 200, 200)">Link 2</a>
...
<table>
<tr>
<td id="flash"></td>
</tr>
</table>

hemebond
09-07-2004, 07:53 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Add Flash element</title>
</head>
<body>
<p><a id="flashlink" href="test.swf">Add Flash object</a></p>
<div id="container"></div>
</body>
<script type="text/javascript">
function addFlash()
{
var flash = document.createElement("object");
flash.setAttribute("type","application/x-shockwave-flash");
flash.setAttribute("data","test.swf");
flash.setAttribute("width","400px");
flash.setAttribute("height","300px");

document.getElementById("container").appendChild(flash);
return false;
}
document.getElementById("flashlink").onclick = addFlash;
</script>
</html>This little experiment has reminded me why I hate Internet Explorer so much. This will not work in Internet Explorer. It throws no errors, the element is added, but it never actually loads. Mozilla Firefox works a charm, but Opera doesn't seem to respect the width and height attributes.

Kor
09-07-2004, 08:45 AM
but it never actually loads

Try looping the function once.

hemebond
09-07-2004, 10:59 PM
Try looping the function once.I don't understand.