Convert a string with HTML Code into an HTML object(Tag)

Asked

Viewed 695 times

1

good morning. I have the following problem:

I am implementing the integration between the company’s mobile application and the VIMEO platform. I’m using the oEmbed type integration, and from their documentation (https://developer.vimeo.com/apis/oembed#examples), when I make the request an XML is returned in which one of the elements() comes with the tag already ready to integrate into the site. This part of recovering the information and passing to the application javscript is already normal, I managed to do it correctly.

The problem occurs when I pass the tag to the html page. It does not interpret as a common html element, but rather as a text. That way, the video doesn’t load on the page.

I wonder how I can perform this text conversion to a type that is interpreted as an HTML tag, so that the video works correctly.

Below is an excerpt of code from an attempt I made in the javascript file to convert text to HTML element, following some examples I saw when I searched.

modulos : function(idCurso, idMatricula){
    var deferred = new $.Deferred();
    var parser = new DOMParser();//<<<CRIA O ELEMENTO DOM
    fn.load('conteudo.html');

    $.ajax({
        url: window.api_url + '/curso/getModulosCurso',
        method: 'GET',
        data: {idCurso : idCurso}
    }).done(function(response){

        $.each(response, function(i,elem){
            $('#select-carousel').append($('<option>', {
                value: elem.IdModulo,
                text: elem.Titulo,
            }));                
            elem.HtmlVimeo = $.parseHTML(elem.HtmlVimeo, "text/html");//<<<CONVERTE A STRING RECEBIDA EM HTML
        });

In this next snippet, as the code is pulled on the main page.

                    {{if TipoConteudo == 'Vídeo MPEG'}}
                        {{:HtmlVimeo}}  <!-- PUXA A VARIÁVEL HtmlVimeo, QUE CONTÉM A TAG HTML
                    {{/if}}

The following is a screenshot of how the HTML page is interpreting the above code:

Imagem da interpretação do HTML

NOTE: To make sure that this section of the variable Htmlvimneo(<iframe src="https://player.vimeo.com/video/116061334?app_id=XXXXX" width="480" height="272" frameborder="0" title="Power Point - Aula 1" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>) That’s right, I copied and pasted it to the location of the second code, to see if the video would work. Functioning was normal, demonstrating that the error is even in this interpretation of the variable as text and not as HTML.

Thanks in advance.

  • Even using parseHTML is going as string?

  • Dude, look at that answer -> https://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements This might help

  • @dvd Yes, even using parseHtml is going as string.

  • @Luizfelipe had already seen this answer, I even went through some of them to try to solve, but still did not solve.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.