JavaScript error for eval parent.location

JavaScript error for eval parent.location

本文关键字:parent location eval for error JavaScript      更新时间:2023-09-26

我在经典ASP工作。我正在使用的代码(不是我的代码)是很久以前写的,甚至可能早在Firefox和Chrome出现之前。

无论如何,有以下JavaScript函数:

function MM_jumpMenu(targ, selObj, restore) {
    eval(targ + ".location ='" + selObj.options[selObj.selectedIndex].getAttribute('value') + "'");
    if (restore)
    {
        selObj.selectedIndex=0;
    }
}

那个代码突然停止工作了,我想找出原因。在Chrome中,它给了我错误:

SyntaxError: Unexpected identifier

当我尝试运行代码时,传入的参数如下:

targ = "parent"

对selObj所选索引的值 = "edit_details.asp?make=ML&n=&r=DA61CHH&c=Hope预混合混凝土有限公司- CHY LCV's&cus=HOPEAG02&type=&inc=&id=&fw=&cusid=HOPE03"

restore = 0

假设代码是专门为IE 6/7编写的,我们正在努力标准化,使其适用于所有浏览器

eval是邪恶的!!不要用它!

window[targ].location = selObj.options[selObj.selectedIndex].getAttribute('value');

url中有一个未转义的单引号。

CHY LCV's&

埃斯佩斯:

CHY LCV''s&

但实际上,这段代码太可怕了,如果可以的话你应该重写一遍。

"value on selected index of selObj ":带有撇号。你需要转义