How to make sure that script / script does not appear in the HTML file. Appear only the text inside document.write

2

I'm trying to insert some scripts of my WHMCS into a HTML page on my site, which returns a document.write(' Texto que irá aparecer '); , and the text contained within document.write is displayed in the HTML page. p>

Tutorial link : link

In order to work, I have to insert several <script></script> which generates many requests.

I would like to make it appear only:

<h1> Text that will appear </h1>

Instead of:

<h1><script language="javascript" src=" "> Text that will appear </script><h1>

Example in JSFiddle

(used for example Hostgator whmcs)

Is there any way to make the text appear only?     

asked by anonymous 24.06.2014 / 01:11

2 answers

4

Using jQuery, you could do the following:

function removeScripts(el) {

    //Para cada elemento que deve ter o script removido
    $(el).each(function () {
        var i = this;

        //remove os espaços em branco
        var value = ($(i).text()).replace(/\s/g, '');

        //verifica se o texto já foi carregado dentro do elemento
        if (value.length > 0) {

            // se sim, remove a tag script do elemento
            $('script', i).remove();
        } else {

            // se não, dá mais 500ms e tenta denovo
            setTimeout(function () {
                removeScripts(el);
            }, 500);
        }
    });
}

And to call the function:

removeScripts('.elementos');

Example: FIDDLE

What this function does is check all the selectors you provided if there is any text (which would be the text loaded by the script element). If it exists, it just deletes the script tag, if it does not exist, this means that the script still can not load the text, so it waits 500 milliseconds and tries again.

    
24.06.2014 / 02:05
0

Javascript is a language that must be run on the client, and therefore it is not possible to completely hide a javascript code. In this case, it is recommended to separate the javascript code from the HTML, into a js file. Then this javascript file can be minified, being transformed into a file more difficult to be read by a human being. An example site that can be used to minify your javascript code can be found here .

    
24.05.2016 / 20:44