Why am I recieving the error 'document.write can be a form of eval'?

↘锁芯ラ 提交于 2019-12-12 04:08:53

问题


This is all I've got going, but my debugger says 'document.write can be a form of eval,' and my jsonString variable prints as undefined. Any help is appreciated, thanks.

function getUrlVars() {
        var map = {};
        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                                                 map[key] = value;
                                                 });
        return map;
    }

    var jsonString = getUrlVars()['json'];
    document.write(jsonString);

回答1:


The reason document.write can be a form of eval is because if you write a script element it will be evaluated.

As for why your jsonString is undefined, you probably don't have a parameter named 'json'.



来源:https://stackoverflow.com/questions/10609957/why-am-i-recieving-the-error-document-write-can-be-a-form-of-eval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!