How do I open a page created with javascript?

2

I was writing a plugin for firefox in which I generate an html with the page in which the plugin acts and I want to show my html generated in another new page, what I have tried has a form quite similar to the following:

function crearHTML(){
    return "<html><head></head><body><p>Hola manola</p></body></html>";
}

function abrirPagina(){

    var html = crearHTML();

    var dataURL = "data:text/html;base64," + btoa(html);

    var w = window.open(dataURL);
}

In theory it should work, but it's like firefox opens the tab and closes it immediately, this does not happen if instead of passing the MIME "text / html" step "text / plain", in which case the page is maintained open but obviously not rendered as I want.
Any idea why this could be happening?

    
asked by Sacha 22.06.2018 в 22:28
source

1 answer

1

You can open it by typing it on the same page like this:

function crearHTML(){
    return "<html><head></head><body><p>Hola manola</p></body></html>";
}

function abrirPagina(){

    var html = crearHTML();

    // var dataURL = "data:text/html;base64," + btoa(html);

    document.write(html);
}

Another method is to create an html file in the same location on the page, example:

function crearHTML(){
        return "<html><head></head><body><p>Hola manola</p></body></html>";
    }

    function abrirPagina(){

      var html = crearHTML();

      var txtFile = new File("example.html");
      txtFile.writeln(html);
      txtFile.close();
      window.open("example.html");
    }
    
    
    
answered by 06.08.2018 в 09:35