Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - come far leggere a un browser creato in java un codice javascript
Forum - Java - come far leggere a un browser creato in java un codice javascript

Avatar
giordanomalandra (Normal User)
Newbie


Messaggi: 15
Iscritto: 29/09/2012

Segnala al moderatore
Postato alle 17:58
Lunedì, 22/10/2012
ho creato un webbrowser in java ora il problema è che navigando su questo browser ho scoperto che viene letto solo il codice html della pagina e non il codice javascript come devo fare per far leggere al mio browser anche il codice javascript ecco il codice GRAZIE 1000
Codice sorgente - presumibilmente Java

  1. package browser;
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import java.net.*;
  12. import java.io.*;
  13.  
  14. public class Browser {
  15.         private JFrame frame;
  16.         private JPanel panelTop;
  17.         private JEditorPane editor;
  18.         private JScrollPane scroll;
  19.         private JTextField field;
  20.         private JButton button;
  21.         private URL url;
  22.  
  23.         public Browser(String titolo) {
  24.                 initComponents();
  25.  
  26.                
  27.                 frame.setTitle(ttolo);
  28.  
  29.              
  30.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.  
  32.              
  33.                 frame.setSize(800,600);
  34.  
  35.              
  36.                 frame.add(BorderLayout.NORTH, panelTop);
  37.  
  38.              
  39.                 panelTop.add(field);
  40.                 panelTop.add(button);
  41.  
  42.            
  43.                 frame.add(BorderLayout.CENTER, scroll);
  44.  
  45.                
  46.              
  47.                 frame.setVisible(true);
  48.         }
  49.  
  50.         private void initComponents() {
  51.                
  52.                 frame = new JFrame();
  53.  
  54.                
  55.                 panelTop = new JPanel();
  56.                
  57.                
  58.                 try {
  59.                         url = new URL("http://www.corrieredellosport.it");
  60.                 }
  61.                 catch(MalformedURLException mue) {
  62.                         JOptionPane.showMessageDialog(null,mue);
  63.                 }
  64.                
  65.            
  66.                 try {
  67.                         editor = new JEditorPane(url);
  68.                         editor.setContentType("text/html");
  69.                      
  70.                        
  71.                         editor.setEditable(false);
  72.                 }
  73.                 catch(IOException ioe) {
  74.                         JOptionPane.showMessageDialog(null,ioe);
  75.                 }
  76.                
  77.              
  78.                 scroll = new JScrollPane(editor);
  79.  
  80.              
  81.                 field = new JTextField();
  82.  
  83.              
  84.                
  85.                
  86.                 SwingUtilities.invokeLater(new Runnable() {
  87.                    public void run() {
  88.                            field.setText(url.toString());
  89.                    }
  90.                 });
  91.  
  92.            
  93.                 button = new JButton("VAI");
  94.                
  95.                
  96.                 button.addActionListener(new ActionListener() {
  97.                         public void actionPerformed(ActionEvent e) {
  98.                                 try {
  99.                                         editor.setPage(field.getText());
  100.                                 }
  101.                                 catch(IOException ioe) {
  102.                                         JOptionPane.showMessageDialog(null, ioe);
  103.                                 }
  104.                         }
  105.                 });
  106.         }
  107.  
  108.         public static void main(String[] args) {
  109.                 SwingUtilities.invokeLater(new Runnable() {
  110.                         public void run() {
  111.                                 new Browser("Simple web browser");
  112.                         }
  113.                 });
  114.         }//end main method.
  115. }


PM Quote
Avatar
LittleHacker (Member)
Guru


Messaggi: 1033
Iscritto: 28/04/2009

Segnala al moderatore
Postato alle 20:55
Lunedì, 22/10/2012
Secondo me è qui il problema:
Codice sorgente - presumibilmente Plain Text

  1. editor.setContentType("text/html");


tu hai impostato il tipo a text e html, quindi lui non ti leggerà mai il javascript, perchè tu gli hai detto(involontariamente) di ignorarlo!
Io non so aiutarti, però fatti una ricerca su google(consigliatissimo), oppure aspetta una risposta dai più esperti(consigliato, ma se vuoi imparare qualcosa non puoi solo chiedere devi anche cercare, scervellarti!)!

Non per incolparti o umiliarti, ma questo codice l'hai copiato da una guida o altro?

:k:

Ultima modifica effettuata da LittleHacker il 22/10/2012 alle 21:00
PM Quote
Avatar
tasx (Dev Team)
Expert


Messaggi: 439
Iscritto: 15/12/2008

Segnala al moderatore
Postato alle 22:22
Lunedì, 22/10/2012

PM Quote