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

    JS recuperare parametri di un file incluso tramite innerHTML

    Dopo aver caricato la pagina test1.htm
    vorrei riuscire a leggere eventuali oggetti all'interno della pagina inclusa
    Codice PHP:
    <HTML>
        <
    HEAD>
            <
    title>test</title>
    <
    script type="text/javascript" language="javascript" >
               
                function 
    setLang()
                {
                    try
                    {
                            
    showContent('test1.htm');
                    }
                    catch(
    e)
                    {}
                }
                function 
    setPage(val)
                {
                    try
                    {
                            
    showContent(val);
                        
    element document.getElementById('innerHTMLtxt');
                        if (
    element)
                        {
                            
    element element.getElementById('test');
                            
    alert(element);
                            if (
    element)
                            {
                                
    alert(element.value);
                            }                        
                        }
                    }
                    catch(
    e)
                    {}
                }
    function 
    GET_XMLHTTPRequest()
    {
        var 
    request;

        
    // Lets try using ActiveX to instantiate the XMLHttpRequest object
        
    try
        {
            
    request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(
    ex1)
        {
            try
            {
                
    request = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(
    ex2)
            {
                
    request null;
            }
        }

        
    // If the previous didn't work, lets check if the browser natively support XMLHttpRequest 
        
    if(!request && typeof XMLHttpRequest != 'undefined')
        {
            
    //The browser does, so lets instantiate the object
            
    request = new XMLHttpRequest();
        }

        return 
    request;
    }
                function 
    showContent(srcPage)
                {


                    try
                    {

                        var 
    myXMLHttpRequest GET_XMLHTTPRequest();
        
                        try
                        {
                            
    myXMLHttpRequest.open("GET"srcPagetrue);
        
                            
    myXMLHttpRequest.onreadystatechange = function () 
                            {
                                
    //Any time the readyState of the XMLHttpRequest object changes this method is called.
                                //Loading is complete when the readyState equals 4, so that's the only value we care about right now.
                                
                                
    if(myXMLHttpRequest.readyState == 4)
                                {
                                    
    element document.getElementById('innerHTMLtxt');
                                    if (
    element)
                                    {
                                        var 
    html myXMLHttpRequest.responseText;

                                        
    element.innerHTML html;
                                    }
                                }
                            };
                        }
                        catch(
    ex2)
                        {
                            
    alert(ex2.message);
                        }
                        
                        
    //Lets fire off the request
                        
    myXMLHttpRequest.send(null);
                    }
                    catch(
    e)
                    {
                        
    alert(e.message);
                    }
                }
            
    </script>
                </HEAD>
        <body>
            <form id="Form1" method="post" runat="server">
                            <div id="tabsMenu">
                                <ul>
                                    [*]
                                        <a href="#" title="Home" onclick="setPage('test1.htm');">
                                            <span>test1</span>
                                        </a>
                                    
                                [/list]
                            </div>
                            <div id="innerHTMLtxt"></div>
                        </form>
        </body>
    </HTML> 
    e quest'altra test1.html
    Codice PHP:
    test1 <div id="test">prova1</div
    sapete se si puo fare?

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Si con indexOf tipo:
    codice:
    element = document.getElementById('innerHTMLtxt'); 
                                    if (element) 
                                    { 
                                        var html = myXMLHttpRequest.responseText; 
    if(html.indexOf("prova1")!=-1){
    Valore trovato faccio l'azione X
                            }else{
    Valore non trovato faccio l'azione Y
    }
                  }
    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.