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

1

0

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);
Mongolian answered 15/5, 2012 at 22:57 Comment(3)
You've described what you have, but you haven't described what your requirements are. What are you trying to achieve?Shockheaded
What "de-bugger" throws an error for document.write? Or did you mean a linter?Indult
See this answer: https://mcmap.net/q/927683/-why-am-i-receiving-this-jsfiddle-error-document-write-can-be-a-form-of-evalHaddington
M
3

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

Myke answered 15/5, 2012 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.