[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Brug af et objekt i Javascript



Hej

For at gøre mine Javascript lidt mere generiske (læs browseruafhængige),
bruger jeg følgende javascript til at tilgå objekter/elementer.

(EKSEMPEL 1)

          function getObj(name)
          {
            if (document.getElementById)
            {
              this.obj = document.getElementById(name);
                  this.style = document.getElementById(name).style;
            }
            else if (document.all)
            {
              this.obj = document.all[name];
                  this.style = document.all[name].style;
            }
            else if (document.layers)
            {
                  this.obj = document.layers[name];
                  this.style = document.layers[name];
            }
          }

Scriptet virker fint og jeg kan uafhængig af browser gøre noget i stil med

(EKSEMPEL 2)

          var f = getObj('player');
          f.style.background = '#ffffff';

Men mit problem er, at jeg ikke kan gøre følgende

(EKSEMPEL 3)

            function stop_player()
            {
              var f = new getObj('player');
              f.stop();
            }

Skønt jeg godt kan gøre følgende

(EKSEMPEL 4)

            function stop_player()
            {
              document.getElementById('player').stop();
            }

Er der nogen, der kan sige, hvorfor eksempel 3 feljer når nu eksempel 4 virker ?

Elementet 'player' er iøvrigt en embedded (player) plugin.

Grunden til, at jeg bruger en funktion som getObj() er nogenlunde denne

         IE                      Mozilla
   document.all[name] ==  document.getElementById(name)

--PMM

+----------------------------------------------------------+
| Se TV over Internettet -- http://www.streamtv.dk/?p=test |
+----------------------------------------------------------+



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *