Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Aggiungere dinamicamente link ad immagine

    Ciao a tutti, sono alle prese con questo problema:

    devo verificare che all'interno di un livello con un determinato ID sia presente una immagine (protrebbe anche non esserci), se +è presente devo fare in modo di renderla linkabile, quindi da una situazione del genere:
    codice:
    [img]path_image[/img]
    ad una situazione semile: è possibile?

    questo è quello che finora ho fatto, ma poi non so più come continuare:
    codice:
    function sostituisci()
    {
      if(document.getElementById("id_livello"))
       {
        if(document.getElementById("id_livello").getElementsByTagName("img")[0].src)
        {
         alert("bene, qui c'è l'immagine");
        }
       else
       {
        alert("qui non c'è l'immagine");
       }
      }
     else
      {
       alert("livello non presente");
      }
    }

  2. #2
    Codice PHP:
    <html>
    <
    head>
    <
    title></title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script type="text/javascript">
    function 
    lookForImg(id,path){
        var 
    eldocument.getElementById(id);
        if(
    el){
        var 
    imgel.getElementsByTagName('img')[0];
            if(
    img){
                var 
    adocument.createElement('a');
                
    a.hrefpath;
                
    img.style.border'0px solid #FFFFFF';
                
    a.appendChild(img);
                
    el.appendChild(a);
                
    //bene, qui c'è l'immagine
                
    return true;
            }
            
    //qui non c'è l'immagine
            
    return null;
        }
        
    //livello non presente
        
    return null;
    }
    window.onload=function(){
     
    alert(lookForImg('id_livello','mypage.html'));
    }
    </script>

    </head>

    <body>
    <div id="id_livello">
    [img]path.jpg[/img]
    </div>
    </body>
    </html> 
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Ciao whisher, lo script è fantastico e già per questo ti ringrazio moltissimo!

    ho un'ultima domanda, ho notato che in una situazione del genere:
    codice:
    [img]path_image[/img] testo testo testo testo testo testo testo testo testo testo testo testo testo testo testo testo
    l'immagine viene praticamente "appesa" alla fine del testo, esiste il modo per mantenerla "visivamente" nella posizione originale?

    Grazie ancora....

  4. #4
    Fatto di corsa e testato solamente
    con FF quindi dacci un occhio

    Codice PHP:
    <html>
    <
    head>
    <
    title></title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script type="text/javascript">
    function 
    lookForImg(id,path){
        var 
    eldocument.getElementById(id);
        if(
    el){
        var 
    imgel.getElementsByTagName('img')[0];
            if(
    img){
                var 
    textimg.nextSibling.nodeValue;
                
    el.removeChild(img.nextSibling);
                var 
    adocument.createElement('a');
                
    a.hrefpath;
                
    img.style.border'0px solid #FFFFFF';
                
    a.appendChild(img);
                
    el.appendChild(a);
                
    el.appendChild(document.createTextNode(text));
                
    //bene, qui c'è l'immagine
                
    return true;
            }
            
    //qui non c'è l'immagine
            
    return null;
        }
        
    //livello non presente
        
    return null;
    }
    window.onload=function(){
     
    lookForImg('id_livello','mypage.html');
    }
    </script>

    </head>

    <body>
    <div id="id_livello">
    [img]path.jpg[/img]
    testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1 testo1
    test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2
    test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3 test3

    </div>
    </body>
    </html> 
    Naturalmente funziona solo se in id_livello la struttura DOM
    è sempre uguale ad esempio se non ci sono elementi nodeType
    1 cioè tag html
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  5. #5
    Grazie mille whisher!
    entro domani lo provo, per ora grazie mille!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.