When using buka_halaman('produk','1') then working but when using variable is not working
function rute(){
//window.onhashchange = function(){
switch(location.hash) {
case location.hash:
var abc = location.hash.split('#')[1]; // ex: domain.com/page.html#produk','1
var def = "'"+abc+"'";
if (abc!=undefined){
alert(def);
buka_halaman(def); //error
buka_halaman('produk','1') //working
}
break;
}
//}
}

答案 0 :(得分:1)
改变这个:
var def = "'" + abc + "'";
到此:
var def = abc;
除非您不需要def
变量,否则您可以直接使用abc
:
buka_halaman(abc, '1');
您的代码将单引号字符放入字符串中。