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

    Sostituire +/n con <br>

    Salve,

    io utilizzo questo script

    function writ() {
    f = window.open();
    f.document.write('<html><head><title>Test pagina</title></head><body>' + document.Form1.text.value+'</body></html>');
    f.document.close();

    Per creare anteprime di pagine web che creo tramite uno script php. Volevo sapere se esiste un modo per far si che nell'antemprima i cambi di rigo ("/n") vengano sostituiti con
    , visto che ora come ora, lo script mi fa vedere tutto quello che c'è nel form come se fosse un rigo solo.
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  2. #2
    prova con:
    codice:
    function writ() {
    f = window.open();
    bodyValue=document.Form1.text.value;
    bodyValue=bodyValue.replace('\r\n','
    ');
    f.document.write('<html><head><title>Test pagina</title></head><body>' +bodyValue+'</body></html>');
    f.document.close();}

  3. #3

    Re: Sostituire +/n con <br>

    Originariamente inviato da valepu
    Per creare anteprime di pagine web che creo tramite uno script php.
    www.php.net/nl2br

    ciao

  4. #4

    Re: Re: Sostituire +/n con <br>

    Originariamente inviato da osvi
    www.php.net/nl2br

    ciao
    non in php ma in javascript (altrimenti sarei nel forum sbagliato )
    comunque grazie dvjack ora lo provo
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  5. #5
    si ok ma visto che hai detto di avere php ti consigliavo di farlo direttamente con quello


  6. #6
    si ma l'anteprima della pagina la faccio in Javascript

    Comunque, con

    bodyValue=document.Form1.text.value;
    bodyValue=bodyValue.replace('\r\n','
    ');

    mi sostituisce solo il primo "\n", non succede nulla per quelli successivi
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  7. #7
    giusto...
    codice:
    bodyValue=document.Form1.text.value;
    bodyValue=bodyValue.replace(/\r\n/g,'
    ');

  8. #8
    codice:
    function cambiainbr(elemento) {
    var elx = document.getElementById(elemento).value;
    esp = /\n/gi;
    elx = elx.replace(esp, "
    ");
    document.getElementById(elemento).value = elx;	
    }
    me li cambia tutti
    (l'ho riadattato, cambiava un altra cosa)

    ciao!

  9. #9
    Si, funziona

    codice:
    function writ() {
    f = window.open();
    var elx = document.Form1.text.value;
    esp = /\n/gi;
    elx = elx.replace(esp, "
    ");
    
    f.document.write('<html><head><title>Test pagina</title></head><body>
    
    [b]' + elx + '</body></html>');
    f.document.close();
    se lascio la riga
    "document.Form1.text.value = elx;" poi mi ritrovo i
    nella textarea dove sto lavorando

    Grazie mille a entrambi, ciao
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

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.