2013-02-26 106 views
4

在jQuery Mobile的:如何從jQuery移動腳本中移除基本標籤?

  • 如何從頁面移除<base href="">標籤
  • 如何禁用基本href?

相關代碼:

// Test for dynamic-updating base tag support (allows us to avoid href,src attr rewriting) 
function baseTagTest() { 
    var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/", 
     base = $("head base"), 
     fauxEle = null, 
     href = "", 
     link, rebase; 

    if (!base.length) { 
     base = fauxEle = $("<base>", { "href": fauxBase }).appendTo("head"); 
    } else { 
     href = base.attr("href"); 
    } 

    link = $("<a href='testurl' />").prependTo(fakeBody); 
    rebase = link[0].href; 
    base[0].href = href || location.pathname; 

    if (fauxEle) { 
     fauxEle.remove(); 
    } 
    return rebase.indexOf(fauxBase) === 0; 
} 

回答

0

的基本元素是jQuery的移動的導航模式的一個關鍵因素,以至於當jQuery的移動網站,瀏覽器無法動態更新的基本元素被加載時,預先考慮與基地的網址。

兩個建議,以解決您的需要:

  1. 使用絕對文件相對路徑,而不是

  2. 使用jQuery Mobile Download Builder和定製你需要爲你jQuery Mobile的應用程序的模塊。我最初的猜測是你想要排除導航模塊來刪除基本元素功能。

+0

感謝主席先生/瑪麗爲您提供指導 – lucky 2013-03-05 17:41:27