2012-04-27 80 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