elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  No abre html desde javascript
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: No abre html desde javascript  (Leído 1,193 veces)
alpachino98

Desconectado Desconectado

Mensajes: 37


Valar Morghulis


Ver Perfil
No abre html desde javascript
« en: 19 Febrero 2019, 16:57 pm »

Hola,
el problema que tengo es que no consigo abrir un html desde javascript usando la funcion "cargar". Quiero que se abra el index donde esta el menu y luego se añada debajo la pagina que se pulse en el menu. Para simplificarlo dejo un ejemplo sencillo que tampoco funciona:

HTML
Código:
<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src = "./js/libCapas.js"></script>
    </head>
    <body onload="Cargar('inicio.html','cuerpo')">
        <div>
            <table>
                <tr>
                    <td><a href="#" onclick="Cargar('inicio.html','cuerpo')">Inicio</a></td>
                    <td><a href="#" onclick="Cargar('iniciar_sesion.html','cuerpo')">Iniciar Sesion</a></td>
                   
                </tr>
           
            </table>
        </div>
        <div id="cuerpo"></div>
    </body>
</html>
HTML
Código:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <table>
    <tr>
        <div>TODO write content</div>
        </tr>
     </table>
    </body>
</html>

javascript
Código:
function invokeScript(divid)
{
var scriptObj = divid.getElementsByTagName("SCRIPT");
var len = scriptObj.length;
for(var i=0; i<len; i++)
{
var scriptText = scriptObj[i].text;
var scriptFile = scriptObj[i].src;
var scriptTag = document.createElement("SCRIPT");
if ((scriptFile != null) && (scriptFile != "")){
scriptTag.src = scriptFile;
}
scriptTag.text = scriptText;
if (!document.getElementsByTagName("HEAD")[0]) {
document.createElement("HEAD").appendChild(scriptTag);
}
else {
document.getElementsByTagName("HEAD")[0].appendChild(scriptTag);
}
}
}
                       
function nuevaConexion()
{
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function Cargar(url, capa)
{
var contenido = document.getElementById(capa);
var conexion = nuevaConexion();
conexion.open("GET", url, true);
conexion.onreadystatechange=function()
{
if(conexion.readyState == 4)
{
contenido.innerHTML = conexion.responseText;
invokeScript(document.getElementById(capa));
}
}
conexion.send(null);                               
}
                                               
function CargarForm(url, capa, valores)
{
var contenido = document.getElementById(capa);
var conexion = nuevaConexion();
conexion.open("POST", url, true);
conexion.onreadystatechange=function()
{
if(conexion.readyState == 4)
{
contenido.innerHTML = conexion.responseText;
invokeScript(document.getElementById(capa));
}
};
conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
conexion.send(valores);
}

function ProcesarForm(formulario, url, capa)
{
var valores="";
for (i=0; i<formulario.elements.length;i++)
{
var nombre = formulario.elements[i].name;
if (nombre!="")
{
if (!((formulario.elements[i].type == "radio") && (!formulario.elements[i].checked)))
{
valores += formulario.elements[i].name + "=";
valores += formulario.elements[i].value + "&";
}
}
}
CargarForm(url, capa, valores);
}

function cargaInicial()
{                           
Cargar('menu.html','menu');
Cargar('inicial.html','capa1');
}


Si alguien me puede decir como consigo cargar el segundo html debajo del primero, usando ese javascript

Gracias.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Swf,html o javascript
Diseño Gráfico
Sirena_Dejavu 6 3,524 Último mensaje 2 Julio 2004, 09:56 am
por theskull
Programacion en HTML, PHP, javascript
PHP
Daniel G 0 1,694 Último mensaje 26 Abril 2007, 16:32 pm
por Daniel G
que es mejor, escribir codigo html desde un echo o html solo
Desarrollo Web
morenochico 1 4,558 Último mensaje 14 Febrero 2011, 19:10 pm
por ~ Yoya ~
Html/javascript Injection
Nivel Web
Dacan 2 5,120 Último mensaje 17 Marzo 2011, 13:49 pm
por Castg!
Ver html generado por javascript
Desarrollo Web
desastro 5 3,778 Último mensaje 13 Septiembre 2011, 08:15 am
por WHK
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines