为什么我收到错误“ document.write可以是eval的一种形式”? [英] Why am I recieving the error 'document.write can be a form of eval'?

查看:198
本文介绍了为什么我收到错误“ document.write可以是eval的一种形式”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我要做的一切,但是我的调试器说 document.write可以是eval的一种形式,并且我的jsonString变量显示为未定义。任何帮助表示赞赏,谢谢。

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

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


解决方案

document.write可能是eval的一种形式是因为如果您编写脚本元素,它将被求值。



关于为什么未定义jsonString的原因,您可能没有名为'json'的参数。 / p>

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);

解决方案

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'.

这篇关于为什么我收到错误“ document.write可以是eval的一种形式”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆