Why does javascript eval work in chrome, safari, but in firefox only when firebug is on?

Thanks to this answer, I was able to get javascript to execute when loading via ExtJS AJAX call.

However, the following code does not work the same in all browsers (on Mac):

  • chrome: it works, a warning appears.
  • safari: it works, a warning appears.
  • firefox: works, but only when Firebug is on, when Firebug is not on, the script is ignored

How can I get javascript to execute through an AJAX call in Firefox without installing Firebug?

Ext.onReady(function(){

    var menuItemStart = new Ext.Panel({
        id: 'panelStart',
        title: 'Start',
        html: 'This is the start menu item.',
        cls:'menuItem'
    });

    var menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        title: 'Application',
        html: 'this is the application page',
        cls:'menuItem'
    });

    var regionMenu = new Ext.Panel({
        region:'west',
        split:true,
        width: 210,
        layout:'accordion',
        layoutConfig:{
            animate:true
        },
        items: [ menuItemStart, menuItemApplication ]
    });

    var regionContent = new Ext.Panel({
        id: 'contentArea',
        region: 'center',
        padding:'10',
        autoScroll: true,
        html: 'this is the content'
    });

    new Ext.Viewport({
        layout: 'border',
        items: [ regionMenu, regionContent ]
    });

    menuItemStart.header.on('click', function() {
        Ext.Ajax.request({
            url: 'content/view_start.php',
            success: function(objServerResponse) {
                regionContent.update(objServerResponse.responseText);
            }
        });
    });

    menuItemApplication.header.on('click', function() {             
        Ext.Ajax.request({
            url: 'content/view_application.php',
            success: function(objServerResponse) {
                var responseText = objServerResponse.responseText;
                console.log(responseText);
                regionContent.update(responseText);
                var scripts, scriptsFinder=/<script[^>]*>([\s\S]+)<\/script>/gi;
                while(scripts=scriptsFinder.exec(responseText)) {
                    eval(scripts[1]);
                }
            }
        });

    });
});

Downloadable base:

<script type="text/javascript">
    alert('inside application view');
</script>
<?php
echo 'this is the application view at ' . date('Y-m-d h:i:s');
?>
+2
source share
3 answers

console.log is your culprit.

, JavaScript, , , :

if(window.console) console.log('whatever');

, , .

+1
console.log(responseText);

. console , Firebug, , .

+3

, console.log , . loadScripts.

0

Source: https://habr.com/ru/post/1778078/


All Articles