Reputation: 14159
This question is in continuation to my existing thread.
Below given is a code section. There is a JavaScript code embedded inside a Table column tag. I want to get rid of the script tag. What can be the other way of calling that JavaScript function that resides in a separate .js file?
<tr>
<td width="599" height="154" valign="top">
<script type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
new fadeshow(fadeimages, 593, 163, 0, 3000, 1, "R")
//new fadeshow(fadeimages2, 163, 225, 0, 3000, 0)/
</script>
</td>
</tr>
Upvotes: 0
Views: 140
Reputation: 1597
I presume that the script writes out some HTML into the table cell. If so, I expect it's using a document.write command internally. And if that's the case, moving it in any meaningful way will probably involve refactoring the script. So if you don't know enough JS to attempt that, I'd just leave it where it is. There are worse travesties than this in the world.
Upvotes: 0
Reputation: 328760
Write a JavaScript function which can find all td
elements on the page. Now, you need an event which says "call fadeshow now". That is usually the onClick event. So in your function, for each td
element, register a new function which calls fadeshow:
td.onclick = function() { fadeshow(this, ...) };
this
will contain the td
element when fadeshow
is executed.
Upvotes: 1
Reputation: 946
You probably want to refactor fadeshow to render itself in a specific element. Then give an ID to your TD (...) and either call your function within the HTML page after you have closed the tag containing the respective TD (v1) or in the global initialization code that you can hook on onload (v2).
You may need to specify a height and width for the TD via CSS to avoid a moving effect.
v1 would look like:
...
</table>
<script type="...">
new fadeshow(fadeimages, 593, 163, 0, 3000, 1, "R",
document.getElementById('fadeshow-goes-here'));
</script>
v2 would look like:
<body onload="applicationInit()">
...
(and you would call fadeshow(...) from within applicationInit).
Upvotes: 2