Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:03 Der er 16 kommentarer og
1 løsning

Ændre baggrundsfarve på Iframe

Jeg vil gerne ændre bagrundsfarve på min iframe. Problemet er at iframe ikke består af en side (scr=).

Min iframe kode ser således ud:

<iframe onBlur="doValueUpdate<%=controlId %>()" id="iView<%=controlId %>" style="width: <%=width %>; height: <%=height %>"></iframe>

Hvad kan jeg gøre?
Avatar billede Slettet bruger
14. oktober 2002 - 23:06 #1
Men, kan du ikke bare lave en side med den baggrunds farve du vil have?
Avatar billede ztyxx Nybegynder
14. oktober 2002 - 23:08 #2
du kan ikke lave en baggrundsfarve i en iframe
Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:10 #3
nowoe >> Desvære ikke. Iframet indgår som en del af en editor som gemer i en access database.
Avatar billede fiskesuppe Nybegynder
14. oktober 2002 - 23:11 #4
<iframe bgcolor="#rrggbb">... </iframe>
virker da fint
Avatar billede pelkjaer Nybegynder
14. oktober 2002 - 23:13 #5
Du siger en editor - så intialiserer du vel også editoren og udseendet af dennes iframes indhold i en javascript init funktion.

Noget alá burde kunne gøre det:

var sHTML = ""
    sHTML += ""
        + "<STYLE>"
        +    "BODY {BACKGROUND-COLOR:#CCCCCC;}"
        + "</STYLE>"
        + "<BODY ONCONTEXTMENU=\"return false\">"
        + "</BODY>"
Avatar billede charlie2000 Nybegynder
14. oktober 2002 - 23:13 #6
lav et dokument med den ønskede farve og prop en "src=" ind i koden
"ZERO problemo"

hæld og lykke med siden
Avatar billede fiskesuppe Nybegynder
14. oktober 2002 - 23:15 #7
<iframe style="background-color:rgb(164,57,12)">Dette burde da også virke</iframe>
Avatar billede pelkjaer Nybegynder
14. oktober 2002 - 23:16 #8
Nej - du kan jo ikke style en iframe's indhold på den måde.
Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:26 #9
pelkjaer >> Jeg er ikke skrap til javascript. Kan du hjælpe lidt mere - her er koden:

<script language="JavaScript">

              var viewMode<%=ewp_controlId %> = 1; // WYSIWYG

              function Init<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.designMode = 'On';
                iHTML<%=ewp_controlId %> = "<%= replace(replace(ewp_value, chr(13) & chr(10), "\r\n"), """", "\""") %>";
               
                setTimeout("iView<%=ewp_controlId %>.document.body.innerHTML = iHTML<%=ewp_controlId %>;", 0);
                setTimeout("iView<%=ewp_controlId %>.focus();", 0);
              }

              function selOn(ctrl)
              {
                ctrl.style.borderColor = '#000000';
                ctrl.style.backgroundColor = '#B5BED6';
                ctrl.style.cursor = 'hand';   
              }
             
              function selOff(ctrl)
              {
                ctrl.style.borderColor = '#D6D3CE'; 
                ctrl.style.backgroundColor = '#D6D3CE';
              }
             
              function selDown(ctrl)
              {
                ctrl.style.backgroundColor = '#8492B5';
              }
             
              function selUp(ctrl)
              {
                ctrl.style.backgroundColor = '#B5BED6';
              }
               
              function doBold<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('bold', false, null);
              }

              function doItalic<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('italic', false, null);
              }

              function doUnderline<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('underline', false, null);
              }
             
              function doLeft<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('justifyleft', false, null);
              }

              function doCenter<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('justifycenter', false, null);
              }

              function doRight<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('justifyright', false, null);
              }

              function doOrdList<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('insertorderedlist', false, null);
              }

              function doBulList<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('insertunorderedlist', false, null);
              }

              function doForeCol<%=ewp_controlId %>()
              {
                var left = (screen.availWidth/2) - (293/2);
                var top = (screen.availHeight/2) - (100/2);

                document.all.__data<%=ewp_controlId %>.value = 'foreColor';
                var colorWin = window.open("colors.ewp.asp?controlId=<%=ewp_controlId %>", 'colors', 'scrollbars=0, toolbar=0, statusbar=0, width=293, height=100, left='+left+', top='+top);
              }

              function doBackCol<%=ewp_controlId %>()
              {
                var left = (screen.availWidth/2) - (293/2);
                var top = (screen.availHeight/2) - (100/2);

                document.all.__data<%=ewp_controlId %>.value = 'backColor';
                var colorWin = window.open('colors.ewp.asp?controlId=<%=ewp_controlId %>', 'colors', 'scrollbars=0, toolbar=0, statusbar=0, width=293, height=100, left='+left+', top='+top);
              }

              function doImage<%=ewp_controlId %>()
              {
                var left = (screen.availWidth/2) - (450/2);
                var top = (screen.availHeight/2) - (429/2);

                var imageWin = window.open('image.ewp.asp?controlId=<%=ewp_controlId %>&path=<%= ewp_imagePath %>', 'images', 'scrollbars=1, toolbar=0, statusbar=0, width=450, height=429, left='+left+', top='+top);
            }

              function doLink<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('createlink');
              }
             
              function doRule<%=ewp_controlId %>()
              {
                iView<%=ewp_controlId %>.document.execCommand('inserthorizontalrule', false, null);
              }
             
              function doFont<%=ewp_controlId %>(fName)
              {
                if(fName != '')
                  iView<%=ewp_controlId %>.document.execCommand('fontname', false, fName);
              }
             
              function doSize<%=ewp_controlId %>(fSize)
              {
                if(fSize != '')
                  iView<%=ewp_controlId %>.document.execCommand('fontsize', false, fSize);
              }
             
              function doHead<%=ewp_controlId %>(hType)
              {
                if(hType != '')
                {
                  iView<%=ewp_controlId %>.document.execCommand('formatblock', false, hType); 
                }
              }
             
              function doCustomInsert<%=ewp_controlId %>(iValue)
              {
                iView<%=ewp_controlId %>.focus();
                var sel = iView<%=ewp_controlId %>.document.selection;
                var theFrame = sel.createRange();
                theFrame.pasteHTML(iValue);
              }

              function doTable<%=ewp_controlId %>()
              {
                var left = (screen.availWidth/2) - (450/2);
                var top = (screen.availHeight/2) - (210/2);

                var imageWin = window.open('table.ewp.asp?controlId=<%=ewp_controlId %>', 'table', 'scrollbars=1, toolbar=0, statusbar=0, width=450, height=210, left='+left+', top='+top);
              }

              function doToggleView<%=ewp_controlId %>()
              { 
                if(viewMode<%=ewp_controlId %> == 1)
                {
                  iHTML = iView<%=ewp_controlId %>.document.body.innerHTML;
                  iView<%=ewp_controlId %>.document.body.innerText = iHTML;
                 
                  // Hide all controls
                  <% if(ewp_showBold= true) then %>
                    document.all.boldBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showItal= true) then %>
                    document.all.italBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showUnde= true) then %>
                    document.all.undeBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showLeftAlign= true) then %>
                    document.all.leftBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showCenterAlign= true) then %>
                    document.all.centBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showRightAlign= true) then %>
                    document.all.rightBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showOrderedList= true) then %>
                    document.all.ordBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showBulletList= true) then %>
                    document.all.unordBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showTextColor= true) then %>
                    document.all.fcolBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showBackColor= true) then %>
                    document.all.bcolBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showLink= true) then %>
                    document.all.linkBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showImage= true) then %>
                    document.all.imageBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showRule= true) then %>
                    document.all.ruleBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>

                  <% if(ewp_showTable= true) then %>
                    document.all.tableBut<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showFontList= true) then %>
                    document.all.selFont<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showSizeList= true) then %>
                    document.all.selSize<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  <% if(ewp_showHeadingList= true) then %>
                    document.all.selHeading<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>

                  <% if(ewp_showCustomInsertList = true AND ewp_numCustomInserts > 0) then %>
                    document.all.selCustomInsert<%=ewp_controlId %>.style.display = 'none';
                  <% end if %>
                 
                  iView<%=ewp_controlId %>.focus();
                  viewMode<%=ewp_controlId %> = 2; // Code
                }
                else
                {
                  iText = iView<%=ewp_controlId %>.document.body.innerText;
                  iView<%=ewp_controlId %>.document.body.innerHTML = iText;
                 
                  // Show all controls
                  <% if(ewp_showBold= true) then %>
                    document.all.boldBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showItal= true) then %>
                    document.all.italBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showUnde= true) then %>
                    document.all.undeBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showLeftAlign= true) then %>
                    document.all.leftBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showCenterAlign= true) then %>
                    document.all.centBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showRightAlign= true) then %>
                    document.all.rightBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showOrderedList= true) then %>
                    document.all.ordBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showBulletList= true) then %>
                    document.all.unordBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showTextColor= true) then %>
                    document.all.fcolBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showBackColor= true) then %>
                    document.all.bcolBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showLink= true) then %>
                    document.all.linkBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showImage= true) then %>
                    document.all.imageBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showRule= true) then %>
                    document.all.ruleBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>

                  <% if(ewp_showTable= true) then %>
                    document.all.tableBut<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>

                  <% if(ewp_showFontList= true) then %>
                    document.all.selFont<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showSizeList= true) then %>
                    document.all.selSize<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>
                 
                  <% if(ewp_showHeadingList= true) then %>
                    document.all.selHeading<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>

                  <% if(ewp_showCustomInsertList = true AND ewp_numCustomInserts > 0) then %>
                    document.all.selCustomInsert<%=ewp_controlId %>.style.display = 'inline';
                  <% end if %>

                  iView<%=ewp_controlId %>.focus();
                  viewMode<%=ewp_controlId %> = 1; // WYSIWYG
                }
              }

              function doValueUpdate<%=ewp_controlId %>()
              {
                // This function updates the hidden form field value
                iHTML = iView<%=ewp_controlId %>.document.body.innerHTML;
                document.all.__control_<%=ewp_controlId %>.value = iHTML;
              }
             
              // Setup the control
              Init<%=ewp_controlId %>();

            </script>
Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:31 #10
charlie2000>> Det er samme forslag som "ztyxx" kom med - desvære duer den ikke i dette tilfælde.
Avatar billede ztyxx Nybegynder
14. oktober 2002 - 23:33 #11
kom ikke med noget forslag :-)
Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:37 #12
sorry det var faktisk "nowoe" som kom med forslaget, men resultatet er det samme
Avatar billede pelkjaer Nybegynder
14. oktober 2002 - 23:45 #13
Jeg kan ikke helt finde ud af din kode - synes den er lidt underlig..
Hvorfor alt det asp her?


Men måske noget alá:

function Init<%=ewp_controlId %>()
              {
    var sHTML = ""
    sHTML += ""
        + "<STYLE>"
        +    "BODY {background-color: #cccccc;}"
        + "</STYLE>"
        + "<BODY ONCONTEXTMENU=\"return false\">"
        + "</BODY>"
                iView<%=ewp_controlId %>.document.designMode = "On"
                iView<%=ewp_controlId %>.document.write(sHTML)

osv..
Avatar billede bennetsen Nybegynder
14. oktober 2002 - 23:58 #14
pelkjaer >> Jeg kan ikke umidelbart få det til at virke, men jeg prøver igen i morgen.
Det er et script jeg har købt (med retighed til at ændre i koden). Så jeg kan ikke sige så meget om koden.
Avatar billede pelkjaer Nybegynder
15. oktober 2002 - 00:01 #15
Det burde nu virke hvis du indsætter fra den eksistrerende Initfunktion og ned til hvor det slutter (hvor jeg ikke skriver mere)
Avatar billede bennetsen Nybegynder
15. oktober 2002 - 00:12 #16
pelkjaer>> Det virker! - tusind tak
Avatar billede pelkjaer Nybegynder
15. oktober 2002 - 10:11 #17
Cool :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester