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

    come richiamare "id" presente in javascript esterno al proprio sito?

    ciao
    ho un javascript di notizie scorrevoli nel quale ho questo pezzo di codice che rende possibile l'impostazione personalizzata di larghezza e altezza quando lo script viene richiamato all'interno di una qualsiasi pagina html

    var curr_width = parseInt(document.getElementById("notizie").offset Width);
    final_width = curr_width + "px";

    var curr_height = parseInt(document.getElementById("notizie").offset Height);
    final_height = curr_height + "px";

    dunque richiamo il javascript nell'html con:

    <div id="notizie"><script type="text/javascript" src="scripts/contenuti_notizie.js" ></script></div>

    finchè richiamo questo javascript nel server che lo ospita nessun problema, mentre se devo farlo utilizzare da un altro sito, ad esempio in questo modo:

    <div id ="notizie" style=" width:400px;background-color:#000000; color:#FFFFFF"><script type="text/javascript" src="http://www.sito.it/scripts/contenuti_notizie.js" ></script></div>

    non funziona più perchè non so come far richiamare id="notizie" presente nel javascript stesso..spero di essermi spiegato, qualcuno ha qualche suggerimento per risolvere il problema perfavore?
    ciao

  2. #2
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Il javascript non puo' operare con contenuti provenienti da domini diversi.

    ciao
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  3. #3
    non mi risulta!! anzi per sicurezza ho riprovato a inserire lo script che avevo prima in un altro dominio e funziona!!
    la modifica che ho citato qua sopra è stata fatta per un semplice motivo: in questo modo inserendo in un div con la formattazione voluta tramite l'attributo style posso anche decidere la larghezza, l'altezza dello script quindi rendendolo personalizzabile

    ecco com'era prima

    //Specify the marquee's width (in pixels)
    var marqueewidth="300px"
    //Specify the marquee's height
    var marqueeheight="25px"
    //Specify the marquee's marquee speed (larger is faster 1-10)
    var marqueespeed=2
    //configure background color:
    var marqueebgcolor="#DEFDD9"
    //Pause marquee onMousever (0=no. 1=yes)?
    var pauseit=1

    e come è diventato poi:

    // pezzo nuovo
    var curr_width = parseInt(document.getElementById("notizie").offset Width);
    final_width = curr_width + "px";

    var curr_height = parseInt(document.getElementById("notizie").offset Height);
    final_height = curr_height + "px";
    // end pezzo nuovo

    var marqueewidth=final_width
    //Specify the marquee's height
    var marqueeheight=final_height
    //Specify the marquee's marquee speed (larger is faster 1-10)
    var marqueespeed=2
    //configure background color:
    var marqueebgcolor=""
    //Pause marquee onMousever (0=no. 1=yes)?
    var pauseit=1


    ovviamente se può essere utile incollo tutto lo scriptino, ma ora il problema è che nel sito dove risiede lo script posso inserire lo script in un div con l'id "notizie"

    <div id="notizie"><script type="text/javascript" src="scripts/contenuti_notizie.js" ></script></div>

    mentre in un dominio esterno no, o almeno io non so se sia possibile richiamare l'id="notizie" in qualche modo...

  4. #4
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Ma i dati che vuoi recuperare tramite javascript risiedono nel tuo dominio o nel dominio esterno?
    Per intenderci id="notizie" dove si trova?
    Ciao.

    P.S. Dato che anch'io sapevo la stessa cosa di Bruno, e tu affermi il contrario posta il link cosi da poterselo studiare meglio.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  5. #5
    dunque

    il sito in questione è un sito di notizie, quindi come servizio per altri siti si vuole dare la possibilità di inserire queste notizie scorrevoli.

    il javascript ovviamente risiede nel dominio del sito di notizie, questo perchè ovviamente periodicamente le notizie vengono cambiate.

    quindi chi vuole usufruire di tali notizie deve inserire nel proprio sito lo script nel punto della pagina dove ritiene opportuno metterle

    questo è il sito che offre le notizie che potete vedere in alto questa è la pagina di un altro sito dove ho richiamato lo script di prova con il vecchio codice funzionante tramite il seguente codice (dovete scorrere la pagina, lo script di prova l'ho messo in basso):

    <div ><script type="text/javascript" src="http://www.nomedelsito.it/scripts/contenuti_prova.js" ></script></div>

    lo script "buono" sta nel sito delle notizie, l'altro di prova nel secondo sito che ho linkato (ma cmq entrambi gli script sono all'interno del dominio del sito di notizie).

    la differenza fra i 2 script è che quello "buono" è personalizzabile (modificabile l'altezza e la larghezza tramite le classi css che posso assegnare al div che lo contiene), mentre quello che vedete nell'altro sito è quello vecchio dove all'interno dello script stesso sono già specificate altezza e larghezza del marquee.

    l'id impostato nel nuovo script è servito proprio per poter personalizzare questi attributi, sennò sarei costretto ad offrire un servizio di notizie scorrevoli preconfezionato senza possibilità di personalizzazione dell'altezza e della larghezza del marquee


    Ecco lo script che non aveva bisogno del richiamo id="notizie", cioè quello vecchio:

    html: <div ><script type="text/javascript" src="http://nomedelsito.it/scripts/contenuti_prova.js" ></script></div>

    script:

    //Specify the marquee's width (in pixels)
    var marqueewidth="300px"
    //Specify the marquee's height
    var marqueeheight="25px"
    //Specify the marquee's marquee speed (larger is faster 1-10)
    var marqueespeed=2
    //configure background color:
    var marqueebgcolor="#DEFDD9"
    //Pause marquee onMousever (0=no. 1=yes)?
    var pauseit=1

    //Specify the marquee's content (don't delete <nobr> tag)
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

    var marqueecontent='<nobr><font face="Arial"> serie di notizie con link </font></nobr>'

    ////NON CAMBIARE NIENTE DI QUESTI PARAMETRI ////////////
    marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
    var copyspeed=marqueespeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var iedom=document.all||document.getElementById
    if (iedom)
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
    var actualwidth=''
    var cross_marquee, ns_marquee

    function populate(){
    if (iedom){
    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
    cross_marquee.style.left=parseInt(marqueewidth)+8+ "px"
    cross_marquee.innerHTML=marqueecontent
    actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
    }
    else if (document.layers){
    ns_marquee=document.ns_marquee.document.ns_marquee 2
    ns_marquee.left=parseInt(marqueewidth)+8
    ns_marquee.document.write(marqueecontent)
    ns_marquee.document.close()
    actualwidth=ns_marquee.document.width
    }
    lefttime=setInterval("scrollmarquee()",20)
    }
    window.onload=populate

    function scrollmarquee(){
    if (iedom){
    if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
    cross_marquee.style.left=parseInt(cross_marquee.st yle.left)-copyspeed+"px"
    else
    cross_marquee.style.left=parseInt(marqueewidth)+8+ "px"

    }
    else if (document.layers){
    if (ns_marquee.left>(actualwidth*(-1)+8))
    ns_marquee.left-=copyspeed
    else
    ns_marquee.left=parseInt(marqueewidth)+8
    }
    }

    if (iedom||document.layers){
    with (document){
    document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
    if (iedom){
    write('<div style="position:relative;width:'+marqueewidth+';he ight:'+marqueeheight+';overflow:hidden">')
    write('<div style="position:absolute;width:'+marqueewidth+';he ight:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
    write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
    write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
    write('</ilayer>')
    }
    document.write('</td></table>')
    }
    }




    Ecco quello nuovo che richiede il richiamo dell'id="notizie", le modifiche dello script sono all'inizio tra il commento // pezzo nuovo

    html: <div id="notizie"><script type="text/javascript" src="http://www.nomedelsito.it/scripts/contenuti_prova.js" ></script></div>

    script:

    //Specify the marquee's width (in pixels)

    // pezzo nuovo
    var curr_width = parseInt(document.getElementById("notizie").offset Width);
    final_width = curr_width + "px";

    var curr_height = parseInt(document.getElementById("notizie").offset Height);
    final_height = curr_height + "px";
    // end pezzo nuovo

    var marqueewidth=final_width
    //Specify the marquee's height
    var marqueeheight=final_height
    //Specify the marquee's marquee speed (larger is faster 1-10)
    var marqueespeed=3
    //configure background color:
    var marqueebgcolor=""
    //Pause marquee onMousever (0=no. 1=yes)?
    var pauseit=1

    //Specify the marquee's content (don't delete <nobr> tag)
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

    var marqueecontent='<nobr><font face="Verdana">serie di notizie con link </font></nobr>'

    //// NON CAMBIARE NIENTE DI QUESTI PARAMETRI ////////////
    marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
    var copyspeed=marqueespeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var iedom=document.all||document.getElementById
    if (iedom)
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
    var actualwidth=''
    var cross_marquee, ns_marquee

    function populate(){
    if (iedom){
    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
    cross_marquee.style.left=parseInt(marqueewidth)+8+ "px"
    cross_marquee.innerHTML=marqueecontent
    actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
    }
    else if (document.layers){
    ns_marquee=document.ns_marquee.document.ns_marquee 2
    ns_marquee.left=parseInt(marqueewidth)+8
    ns_marquee.document.write(marqueecontent)
    ns_marquee.document.close()
    actualwidth=ns_marquee.document.width
    }
    lefttime=setInterval("scrollmarquee()",20)
    }
    window.onload=populate

    function scrollmarquee(){
    if (iedom){
    if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
    cross_marquee.style.left=parseInt(cross_marquee.st yle.left)-copyspeed+"px"
    else
    cross_marquee.style.left=parseInt(marqueewidth)+8+ "px"

    }
    else if (document.layers){
    if (ns_marquee.left>(actualwidth*(-1)+8))
    ns_marquee.left-=copyspeed
    else
    ns_marquee.left=parseInt(marqueewidth)+8
    }
    }

    if (iedom||document.layers){
    with (document){
    document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
    if (iedom){
    write('<div style="position:relative;width:'+marqueewidth+';he ight:'+marqueeheight+';overflow:hidden">')
    write('<div style="position:absolute;width:'+marqueewidth+';he ight:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
    write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
    write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
    write('</ilayer>')
    }
    document.write('</td></table>')
    }
    }

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Prova a racchiudere le impostazioni nel onload cosi:
    codice:
    // pezzo nuovo
    window.onload=function(){
    var curr_width = parseInt(document.getElementById("notizie").offsetWidth);
    final_width = curr_width + "px";
    
    var curr_height = parseInt(document.getElementById("notizie").offsetHeight);
    final_height = curr_height + "px";}
    // end pezzo nuovo
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    ok ci provo, e in pratica in questo modo potrò richiamare lo script in pagine html di altri siti includendo anche id="notizie" :master: :master: cioè pensi che con sta modifica mi funzionerà <div id="notizie"><script type="text/javascript" src="http://www.nomedelsito.it/scripts/contenuti_prova.js" ></script></div> ??

    grazie

  8. #8
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Partendo che il mark up del div notizie sia definito nel sito originario, non nel sito che fornisce le notizie, con lo script "modificato" ridefinisci le dimensione dello script stesso.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

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.