IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Problème avec un élément wyzwyg... (iframes)


Sujet :

JavaScript

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 12
    Points : 10
    Points
    10
    Par défaut Problème avec un élément wyzwyg... (iframes)
    j'ai un code javascript (ci-dessous) qui initialise des IFrames à la place de textareas. Un souci persiste : je ne peux éditer que la dernière IFrame créée...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
    //initialise RTE editor
    function initialiseWebWizRTE(){
     
        //début code ajouté
        var i
        for(i=0;i<NomTextArea.length;i++)
        {
        //fin code ajouté
            var textArea = document.getElementById(NomTextArea[i]);
            var textAreaWidth = parseInt(textArea.offsetWidth);
            var textAreaHeight = parseInt(textArea.offsetHeight);
            //hide textarea
            textArea.style.display = 'none';
     
            //create the iframe
            var iframe = document.createElement('iframe');
            iframe.setAttribute('id', NomsIFrame[i]);
            iframe.setAttribute('onfocus', 'strIFrameName=this.id;');
            textArea.parentNode.insertBefore(iframe, textArea);
     
            //style iframe
            iframe.style.width = textAreaWidth + 'px';
            iframe.style.height = textAreaHeight + 'px';
            iframe.style.border = '#A5ACB2 1px solid';
     
            //make toolbar the same size
            document.getElementById('toolbar').width = textAreaWidth + 2 + 'px';
     
            var editor = document.getElementById(NomsIFrame[i]).contentWindow.document;
     
            //create iframe page content
            var iframeContent;
            iframeContent  = '<html>\n';
            iframeContent += '<head>\n';
            iframeContent += '<link href="RTE_configuration/default_style.css" rel="stylesheet" type="text/css" />\n';
            iframeContent += '<style>html,body{border:0px;background-color:<% = strRTEbackgroundColour %>;}\ntd{border:1px dotted #CCCCCC;}\n</style>\n';
            iframeContent += '</head>\n';
            iframeContent += '<body leftmargin="1" topmargin="1" marginwidth="1" marginheight="1" class="RTEtextarea">\n';
            iframeContent += textArea.value;
            iframeContent += '</body>\n';
            iframeContent += '</html>';
     
            editor.open();
            editor.write(iframeContent);
            editor.close();
     
            function initIframe(){
        <%
     
        'IE uses contentEditable instead of designMode to prevent runtime errors in IE6.0.26 to IE6.0.28
        'IE uses proprietary attachEvent instead of following the W3C Events module and using addEventListener
        'IE SUCKS!!
        If RTEenabled = "winIE" Then
     
        %>        
                editor.attachEvent('onkeypress', editorEvents);
                editor.attachEvent('onmousedown', editorEvents);
                document.attachEvent('onmousedown', hideIframes);
                editor.body.contentEditable = true;
        <%
     
        'Gekco needs designMode enabled AFTER we listen for events using addEventListener
        Else
        %>        editor.addEventListener('keypress', editorEvents, true);
                editor.addEventListener('mousedown', editorEvents, true);
                document.addEventListener('mousedown', hideIframes, true);
                editor.designMode = 'on';
        <%
        End If
     
        %>    }
            setTimeout(initIframe, 300);        
            //get present onsubmit events
            if (typeof textArea.form.onsubmit == 'function'){
                textArea.form.originalOnSubmit = [];
                textArea.form.originalOnSubmit.push(textArea.form.onsubmit);
            }
     
            //get textrea value from RTE and run any original onSubmit events
            textArea.form.onsubmit = function(){
                textArea.value = editor.body.innerHTML;
                for (i in this.originalOnSubmit){
                    return this.originalOnSubmit[i]();
                }
            }
     
            //resetting the form
            textArea.form.onreset = function(){
                if (window.confirm('<% = strResetWarningFormConfirm %>')){
                    editor.body.innerHTML = '';
                    return true;
                }
            return false;
            }
     
            //unload event so we don't loose the data
            window.onunload = function(){
                textArea.value = editor.body.innerHTML;
            }
        }
    }
    Avec comme déclaration :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    NomTextArea=new Array(""visuel"",""informations"");
    NomsIFrame=new Array(""visuel1"",""informations1"");
    Sinon encore un problème : J'aimerais modifier une variable Javascript lors de l'édition d'une iframe (pas moyen de faire marcher onfocus avec le code précédent :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    iframe.setAttribute('onfocus', 'strIFrameName=this.id;');
    )

    Si quelqu'un a une des 2 solutions... merci

  2. #2
    Membre actif
    Homme Profil pro
    Inscrit en
    Avril 2006
    Messages
    245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations forums :
    Inscription : Avril 2006
    Messages : 245
    Points : 239
    Points
    239
    Par défaut
    Citation Envoyé par nasgektw
    iframe.setAttribute('onfocus', 'strIFrameName=this.id;');
    sous ie je pense plutot à ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    iframe.onfocus = function() {strIFrameName=this.id; }
    pour le reste, qu'est ce que çà doit afficher pasque là je vois pas ou peut etre l'erreur ...

Discussions similaires

  1. Réponses: 2
    Dernier message: 03/10/2009, 21h31
  2. [AJAX] avec un élément draggable
    Par dilol34 dans le forum AJAX
    Réponses: 2
    Dernier message: 16/03/2009, 17h48
  3. [SimpleXML] Problème avec simpleXML : il n'affiche pas le contenu de mon élément
    Par ploxien dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 05/05/2007, 19h43
  4. Problème avec les IFRAME
    Par cinemania dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 20/10/2006, 17h12
  5. Problème avec un iframe, tout se décale
    Par Link14 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 22/10/2005, 13h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo