|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
[javascript] [Firefox] Problema Submit Form
Ciao a tutti! sto sviluppando un'extension per firefox per velocizzarmi alcune operazioni.
Praticamente al context-menu di Firefox aggiungo un link per tradurre una parola selezionata. Il sito su cui mi appoggio richiede una form con metodo POST per inviare le richieste, quindi tramite il javascript mi creo una form apposita. Ho provato il javascript tramite una pagina html di prova e tutto funziona, mentre la stessa funzione chiamata nell'estensione firefox si blocca prima del myForm.submit(). Codice:
function sendForm(search_p) // search_p è la parola selezionata { // Creo la mia FORM var myForm = document.createElement("form"); myForm.method = "POST"; myForm.action = "URL DEL SITO "; myForm.name = "NOME FORM"; myselect=document.createElement("select"); myselect.name = "lingua"; opzioni=document.createElement("option"); opzioni.value = "ingita"; // Etc etc...Codice non importante // .... myselect.appendChild(opzioni); myForm.appendChild(myselect); // Questa riga l'ho rimossa in quanto si bloccava..a quale // document dovrebbe fare riferimento? // document.body.appendChild(myForm); // Senza la riga precedente fino a qui arriva zenza problemi // ma non fa la richiesta myForm.submit(); } Spero di essere stato chiaro..qualche idea? ![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
Aggiungo che la console degli errori di Firefox mi segnala come errore
document.body has no properties sulla riga --> document.body.appendChild(myForm); o rimuovendola lo stesso errore ma per la form --> myForm.submit(); Ho cercato informazioni sull'errore ma non ho trovato nessuna soluzione ![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#3 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
up up..nessuno ha anche un minimo suggerimento?
![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Ciao, il fatto è che non sei nell'ambiente "finestra" come se scrivessi un semplice script js.
Sei dentro al browser, e per ricavare l'oggetto document della pagina html devi fare Codice:
htmlDoc=gBrowser.contentDocument; |
![]() |
![]() |
![]() |
#5 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
Grazie per l'aiuto! ma ho ancora quel problema
![]() In questo modo dovrei usare il document della pagina corrente...è corretto? Codice:
function sendForm(search_p) { htmlDoc = gBrowser.contentDocument; alert("Entrato in sendForm ... Document = " + htmlDoc ); // htmlDoc restituisce [object XPCNativeWrapper [object HTMLDocument]] myForm = document.createElement("form"); myForm.method = "POST"; myForm.action = " URL SITO "; myForm.name = " NOME FORM"; alert("Form creata!"); myselect=document.createElement("select"); myselect.name = "lingua"; opzioni=document.createElement("option"); opzioni.value = "ingita"; search=document.createElement("input"); search.name = "parola"; search.type = "text"; search.value = search_p; b=document.createElement("input"); b.name = "ut"; b.type = "hidden"; b.value = "1"; alert("Prima degli append!"); myselect.appendChild(opzioni); myForm.appendChild(myselect); myForm.appendChild(search); myForm.appendChild(b); htmlDoc.body.appendChild(myForm); alert("Ok prima del submit!"); htmlDoc.myForm.submit(); alert("Ok dopo submit!"); return; } Credo che sia un errore banale ma non ci arrivo ![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Codice:
htmlDoc.myForm.submit(); dovresti fare Codice:
myForm.submit(); Codice:
htmlDoc.getElementById(idForm).submit(); |
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Ma comunque in questo modo viene creato e aggiunto un form alla pagina che stai visualizzando sul browser!
E' questo che vuoi ottenere? Io avevo capito quello vedendo il tuo document.body... Se invece te ti sei creato un file.XUL che fa l'override del context-menu dove aggiungi il tuo form allora va bene usare document(in quanto document si riferisce a quel file) ma non esiste nessun body! Codice:
function sendForm(search_p) // search_p è la parola selezionata { // Creo la mia FORM var myForm = document.createElement("form"); myForm.method = "POST"; myForm.action = "URL DEL SITO "; myForm.name = "NOME FORM"; myselect=document.createElement("select"); myselect.name = "lingua"; opzioni=document.createElement("option"); opzioni.value = "ingita"; // Etc etc...Codice non importante // .... myselect.appendChild(opzioni); myForm.appendChild(myselect); // Questa riga l'ho rimossa in quanto si bloccava..a quale // document dovrebbe fare riferimento? document.appendChild(myForm); // Senza la riga precedente fino a qui arriva zenza problemi // ma non fa la richiesta myForm.submit(); } Ultima modifica di MEMon : 23-11-2007 alle 14:10. |
![]() |
![]() |
![]() |
#8 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
No no..io dopo aver selezionato una parola voglio chiamare una pagina che ricevendo una richiesta POST con tale parola, ne fa la traduzione.
Non so dove debba essere messo sto maledetto form ![]() Quindi: - seleziono la parola - dal context-menu di firefox chiamo la funzione js, che si occupa di creare la form e farne il submit...e mi aspetto la risposta con traduzione a browser ![]() Con il codice che mi hai postato per ultimo mi da questa eccezione sul Codice:
document.appendChild(myForm); "Node cannot be inserted at the specific point in the hierarchy" code 3...etcetc...(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR) ![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#9 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Ma sei sicuro che puoi fare una chiamata post ad una pagina fuori dal tuo dominio?
Comunque con l'ultimo codice si mi sono dimenticato che gli devi dare un "contenitore" dove inserire il tuo form. Ma quel codice serve se vuoi attaccare il form ad una finestra della TUA estensione o ad una parte di firerfox. Posta il codice del tuo file XUL anche. Altrimenti devi usare il primo, che ti andrà ad inserire il form nella pagina html che stai visualizzando. Ma non so se poi puoi fare un submit... |
![]() |
![]() |
![]() |
#10 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
Eh non so bene se sia possibile, avevo anche io dubbi del genere.
Facendo una MIA pagina di prova con inserito il javascript che aggiunge la form funziona tutto...ma su una pagina che visualizzo su firefox,attraverso i js richiamato dal context-menu? ![]() Ti posto lo xul, comincio a capirci sempre meno ![]() Codice:
<?xml version = "1.0"?> <overlay id = "hoepliSearch" xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/x-javascript" src="hoepliSearch.js"/> <script type="application/x-javascript" src="imdbSearch.js"/> <popup id = "contentAreaContextMenu"> <menuseparator id="k-tools-separator1"/> <menu id="k-tools-context" class="menuitem-iconic" image="" label="k-tools"> <menupopup> <menuitem id = "hoepliSearch" label = "Translate ENG - ITA" accesskey = "E" insertafter = "context-stop" oncommand = "searchInHoepli();" /> <menuitem id = "hoepliSearch" label = "Translate ITA - ENG" accesskey = "I" insertafter = "context-stop" oncommand = "searchInHoepli();" /> </menupopup> </menu> </popup> </overlay>
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#11 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Ok se hai fatto una prova su una pagina esterna al dominio e funziona allora va bene.
Siccome il form inteso come quello HTML non c'è in XUL non puoi aggiungerlo ad un file XUL ma solo ad un DOM di una pagina html. Quindi crei il tuo form, lo imposti come invisibile, e lo attacchi alla pagina html che stai visualizzando, poi ci fai quel che vuoi: Codice:
function sendForm(search_p) // search_p è la parola selezionata { htmlDoc = gBrowser.contentDocument; // Creo la mia FORM var myForm = document.createElement("form"); myForm.setAttribute("id","autoSearchingForm"); myForm.method = "POST"; myForm.action = "URL DEL SITO "; myForm.name = "NOME FORM"; myForm.setAttribute("style","display:none"); myselect=document.createElement("select"); myselect.name = "lingua"; opzioni=document.createElement("option"); opzioni.value = "ingita"; // Etc etc...Codice non importante // .... myselect.appendChild(opzioni); myForm.appendChild(myselect); htmlDoc.appendChild(myForm); htmlDoc.getElementById("autoSearchingForm").submit(); } |
![]() |
![]() |
![]() |
#12 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
Ho provato entrambi...usando
Codice:
document.createElement(el) Codice:
htmlDoc.createElement(el) Codice:
myselect.appendChild(opzioni); myForm.appendChild(myselect); myForm.appendChild(search); myForm.appendChild(b); htmlDoc.appendChild(myForm); htmlDoc.getElementById("autoSearchingForm").submit();
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#13 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Si ci vuole il body sta volta visto che lavori sulla pagin html scusa...
prova con htmlDoc.body.appendChild sorry ![]() e se il body non lo prende prova con htmlDoc.getElementsByTagName("body")[0] |
![]() |
![]() |
![]() |
#14 |
Member
Iscritto dal: May 2003
Messaggi: 93
|
siiiiiiiiiiiiii...funziona!!
![]() ![]() Ha preso Codice:
htmlDoc.body.appendChild Codice:
function sendForm(search_p) { htmlDoc = gBrowser.contentDocument; var myForm = htmlDoc.createElement("form"); myForm.setAttribute("id","autoSearchingForm"); myForm.method = "POST"; myForm.action = "http://edigeo-online.it/cgi-local/Hoepli/findnr"; myForm.name = "frmDictSearch"; myForm.setAttribute("style","display:none"); myselect = htmlDoc.createElement("select"); myselect.name = "lingua"; opzioni = htmlDoc.createElement("option"); opzioni.value = "ingita"; search = htmlDoc.createElement("input"); search.name = "parola"; search.type = "text"; search.value = search_p; b = htmlDoc.createElement("input"); b.name = "ut"; b.type = "hidden"; b.value = "1"; myselect.appendChild(opzioni); myForm.appendChild(myselect); myForm.appendChild(search); myForm.appendChild(b); htmlDoc.body.appendChild(myForm); htmlDoc.getElementById("autoSearchingForm").submit(); return; } ![]() ![]() ![]()
__________________
...Time to bring it down again. Don't just call me pessimist. Try and read between the lines... |
![]() |
![]() |
![]() |
#15 |
Senior Member
Iscritto dal: Dec 2002
Messaggi: 3359
|
Perfetto!
|
![]() |
![]() |
![]() |
#16 |
Junior Member
Iscritto dal: Sep 2008
Messaggi: 13
|
pagine html dinamiche dentro plugin
Ciao a tutti, ho fatto delle pagine in html e javascript e dovrei inserirle adesso all'interno di un plugin scritto in js e xul. Le pagine sono dinamiche, con delle form e dei pulsanti, ed in base alla selezione si viene direzionati su pagine differenti. Esistono dei metodi già implementati per creare pagine html dentro codice javascript del plugin o in modo xul. Qualche metodo efficace e veloce, per non dover riscrivere tutto il codice o ricorrere alla creazione nodo per nodo tramite dom. Aspetto vostre notizie..suggerimenti, guide, link. HELP ME PLEASE
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:30.