2012-04-27 49 views
0

我有一些javascript可以将页面导向到一个新的url,但是我被定向到了一个www.myurl.com/undefined。javascript url undefined重定向

这是我有,不知道什么是错的。我曾尝试也window.location的

if (r == true) { 
    window.location.href = ('http://www.myurl.com/pubs_delete.php?=id'.a_href) 
}; 

谢谢你的任何指针

+1

你不需要围绕URL的变形 – 2012-04-27 12:56:54

+2

而JavaScript使用'+'来拼接,而不是'.' – ThiefMaster 2012-04-27 13:01:49

回答

1

使用+()sympol尝试这样的事情

 var a_href; 
     if (r == true) { 
      window.location.href = ('http://www.myurl.com/pubs_delete.php?=id'+a_href) 
     }; 

JavaScript的串联,您正在使用()sympol,这是问题的ü

1
if (r == true) { 
    window.location.href = 'http://www.myurl.com/pubs_delete.php?id=' + a_href 
}; 
+0

谈一个简单的15分:) – 2012-04-27 12:57:07

+0

'?= id'应该是'?id = ...'而不是 – fcalderan 2012-04-27 13:00:05

+0

你说得对,我编辑了我的答案。 – gabitzish 2012-04-27 13:01:13

1

假设a_href是在JavaScript中定义的变量

...delete.php?id=' + a_href 

字符串连接为+,不.和等于错位

+0

谢谢,我必须尝试 – 2012-04-27 13:01:57

1

结合两个答案:

if (r) { // r == true is quite redundat 
    window.location.href = "http://www.myurl.com/pubs_delete.php?id=" + a_href; 
}; 
+0

+1'if(r){...' – fcalderan 2012-04-27 13:01:38