Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] componentized html

Started by EvilCrap Sep 15, 2005 at 12:21 PM 1 replies 1k views
Original Post
EvilCrap
EvilCrap
Whats the best way to go about creating html/&#106avascript components? Ive thought to do this:

 <iframe id="ifcomponent1"></iframe>
 <script language="javascript">
  component1= new Component( "ifcomponent1", params );
 </script>

where we create an iframe, and then let the component write out its contents to it. however, it would be cooler to do something like this:

 <script language="javascript>
  component1 = new Component( params );
 </script>

where the component will write out its own iframe and then its components. The problem here though is that the page would refresh and start some strange recursion. How are html/&#106avascript components normally done?
twanvl
twanvl
Most components don't need an iframe. The best thing to do is use a normal HTML element that best approaches the functionalty of the component (so your page is still useable with &#106avascript disabled), then replace that element using DOM:
<input type="text" name="start_date" class="date_picker" id="date_picker1" />// called in onloadfunction init_components() {    // you could instead enumerate all nodes with a specific class    add_date_piceker(document.getElementById("date_picker1"));}function add_date_picker(node) {    var my_component = document.createElement("div");    // create more stuff as needed    node.parentNode.replaceNode(node, my_component);}
EvilCrap
EvilCrap
Yes, this is what I want to do I guess. Earlier I had my mind wrapped around the document.write.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.