[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
 

Re: [PROGRAMMERING] Brug af et objekt i Javascript



Hej


Jeg fandt selv svaret på nedenstående. Mads' spørgsmål pegede mig i den rigtige retning. Jeg troede, at

var f = getObj(name);

gav mig en reference til f.eks. et objekt med id=name.
Men det gør jeg jo ikke. Jeg får bare en reference til
et nyt objekt, der så peger på objektet name og objektets style og
af en eller anden grund kan man så ikke kalde objektets metode
play() og stop().

Men tilføjer jeg et par linier ser det ud til at virke.

>           function getObj(name)
>           {
>             if (document.getElementById)
>             {
>               this.obj = document.getElementById(name);
>               this.style = document.getElementById(name).style;

                this.play = document.getElementById(name).play;
                this.stop = document.getElementById(name).stop;

>             }
>             else if (document.all)
>             {
>               this.obj = document.all[name];
>               this.style = document.all[name].style;

                this.play = document.all[name].play;
                this.stop = document.all[name].stop;

>             }
>             else if (document.layers)
>             {
>                   this.obj = document.layers[name];
>                   this.style = document.layers[name];

                    this.play = document.layers[name];  // Det her går nok ikke
                    this.stop = document.layers[name];  // Det her går nok ikke

>             }
>           }


Er der nogen, der ved hvorfor det er sådan ?


--PMM

Peter Maersk-Moller wrote:
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 |
+----------------------------------------------------------+


--
+----------------------------------------------------------+
| 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] *