external HTML in div without server

0

I own an Index.html page is a series of other html pages. I need to make clicking on a link the specific document appear in a div. Detail, I can not use PHP include because I can not mount a server for different reasons. I can not use the load because it only works on the server. Can anyone give me an idea how to do this miracle? I intend to use electron to envelop everything, but by testing the load did not work on the electron tbm. Is there any jquery load way to run when running html in browser or some other way to make an external html be written directly into dom without serverside?

    
asked by anonymous 19.04.2017 / 05:04

3 answers

1

One thing I think can work.

I'm assuming you have a main div with main-content ID where you'll load the other pages.

function load_home() {
   document.querySelector("#main-content").innerHTML='<object type="text/html" data="PAGINA-HOME.html" ></object>';
}

When user clicks on certain button or link you call this function

If you have a server that only runs HTML and needs route management, you can also use angular, so you have exactly what you described.

A home page where only code snippets change.

See this simple example of w3c.

link

    
19.04.2017 / 05:35
1

Save a JS file or include it in the index, with the following content:

function abre(arquivo,alvo){ 
var xmlHttp; try{ xmlHttp=new XMLHttpRequest(); }
catch (e){ try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e){ alert("Seu navegador não suporta AJAX. Atualize-o"); return false; } } }
xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState == 1) { document.getElementById(alvo).innerHTML = "<img src='images/loading.gif' align='absmiddle'>"; }
if(xmlHttp.readyState == 4) { document.getElementById(alvo).innerHTML = xmlHttp.responseText; } }
xmlHttp.open("GET",arquivo,true); xmlHttp.send(null);  };

Then just put the link:

<a href="javascript:abre('sobre.html','divEscolhida');">Sobre a Empresa</a>

<div id="divEscolhida"></div>
    
19.04.2017 / 05:51
1

It would not be better to do a simple ajax via javascript giving request from the html file, and in this request do you play the content where you need it?

You can also create these html files only with the necessary content without the body and head tags, only what really matters ...

MORE ...

Within its various limitations, you can use angularJS or some other javascript framework to achieve what you need in a much more efficient way than this.

Jquery is cool for the simple thing in SPA, but if you are doing something more elaborate, some framework better.

    
19.04.2017 / 12:53