2012-07-26 65 views
1

大家好,我來自一個HTML頁面導航到另一個:window.location的不正常工作

window.location = "test.html"; 

在test.html中我有標題爲:

<script type="application/javascript"> 

      function redirect() 
      { 
       alert("inside redirect:"); 
       //window.location = url; 
       //history.back(); 
       history.go(-1); 
       return false; 

      } 

     </script> 

     <div data-role="navbar"> 
      <ul> 

       <li> <a href="#" data-theme="b" onclick="history.back(); return false;">Go Back</a></li> 
       <li> <a onclick="redirect()" data-icon="back" data-iconpos="notext" data-direction="reverse" class="ui-btn-left jqm-home">Back1</a></li> 

      </ul> 
     </div> 

但在這裏都後退按鈕(後退和後退1)不起作用。如果我使用$.mobile.changePage('test.html')在頁面之間導航,那麼兩個「後退」按鈕都可以工作。爲什麼他們不與windows.location?

我想爲不支持ajax的B級瀏覽器開發此應用程序。所以我不能使用$.mobile.changePage('test.html')

任何幫助將不勝感激。謝謝。

+0

你特別關注哪個移動設備和操作系統?黑莓OS 5? – 2012-07-26 07:14:29

+0

是的。如果我使用window.location.assign(「first.html」);那麼它從test.html導航到first.html,但當我按下移動(硬件按鈕)的按鈕,然後再次導航到test.html – PPD 2012-07-26 08:18:49

+0

$ .mobile.changePage('test.html')中的問題是什麼'它的工作原理非常好... – 2012-07-26 08:34:29

回答

1

黑莓OS 5瀏覽器有很多問題的屬性。起初我也試圖做你現在正在做的事情。但後來我認爲你必須考慮其他更好的方法。這是我如何解決它

首先加載了jQuery移動這樣的腳本

<script type="text/javascript"> 
    $(document).bind("mobileinit", function() { 
     $.support.cors = true; 
     $.mobile.allowCrossDomainPages = true; 
    }); 
</script> 

前添加這些行然後我用的單個HTML概念。在這個概念中,我只需要加載我的腳本一次,我就可以使用jquery-mobile的changePage。當我有很多html頁面時,我必須等待幾秒鐘,因爲加載和卸載腳本發生。避免這種情況,它的限制。

與在相同的HTML這樣

<div data-role="page" id="page1"> 
<div data-role="page" id="page2"> 
. 
. 
. 

所有頁面然後後,你可以很容易地做一個changePage這樣

$.mobile.changePage("#page1", { 
    transition : "slide" 
}); 

我希望你採取正確的方法。

+0

我用BB5試了一下。我有三個HTML文件1,2,3.html。在每個文件中都有單個按鈕和onclick按鈕,我稱$ .mobile.changePage('2.html')。但是當我從1到2.html顯示一個進度條(不添加我)和2.html不顯示,這裏它仍然顯示one.html進度條。在第二種情況下,我只有1.html和2.html這裏單擊one.html按鈕它顯示2.html但這裏也顯示進度條。在這兩種情況下,相同的代碼在BB6上運行完美。 – PPD 2012-07-26 09:56:18

+0

正是......這就是爲什麼我說要把所有的代碼放在一個HTML中...... – 2012-07-26 10:03:37

+0

但是我有很多的html文件,是不是所有的頁面都放在單個html文件中? – PPD 2012-07-26 10:07:22

0

嘗試:

window.location.href = "test.html"; 

OR:

window.location.assign("test.html"); 

SEE REFERENCE

+1

with window.location.href也不能解決問題。 – PPD 2012-07-26 06:05:53

+0

然後嘗試'window.location.assign(「test.html」);' – 2012-07-26 06:08:50

+0

謝謝你的迴應。但是window.location.assign(「test.html」); 也不能正常工作 – PPD 2012-07-26 06:13:47

0

爲什麼不使用window.location.replace("test.html");

+0

window.location.replace(「test.html」);也沒有解決問題。 – PPD 2012-07-26 06:09:04

0

在jQuery手機中,您可以通過設置一些initiation變量來關閉ajax。您需要加載該腳本加載jQuery Mobile的

$(document).bind("mobileinit", function(){ 
    //apply overrides here 
    $.mobile.ajaxEnabled = false; 
}); 

與阿賈克斯之前已關閉,現在仍然可以使用您的$ .mobile.changePage()。

我們創建一個後退按鈕所有你需要做的就是給的鏈接的data-rel="back"

<li><a href="#" data-theme="b" data-rel="back">Go Back</a></li>