2012-07-25 28 views
1

我目前正在爲我的大學開發WP7應用程序,並且需要臨時解決問題。現在這個解決方案是,我將使用WP7的Web瀏覽器控件加載一個網頁。例如:http://m.iastate.edu/laundry/隱藏網頁中的元素,同時使用WP7的網頁瀏覽器控件

現在,您在網頁上看到了某些要隱藏的元素,例如後退按鈕。現在,我做了什麼處理後退按鈕是這樣的:

private void webBrowser1_Navigating(object sender, NavigatingEventArgs e) 
{ 
    // Handle loading animations 

    // Handle what happens when the "back" button is pressed 
    Uri home = new Uri("http://m.iastate.edu/"); 

    // The the current loading address is home 
    // Cancel the navigation, and go back to the 
    // apps home page. 
    if (e.Uri.Equals(home)) 
    { 
     e.Cancel = true; 
     NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 
    } 

} 

現在工作很漂亮,除了有硬件上後退按鈕的部分。

所以我的第二個選擇是完全隱藏在該頁面上的後退按鈕,而不是它的子女。所以http://m.iastate.edu/laundry/l/0

我仍然爭論不休,只是解析數據,並以我個人的風格顯示出來,但我如果這是完全需要看到的數據是如何需要不斷的互聯網服務,並已經處於不確定精心製作的格式。另外,我覺得這樣會浪費資源?拋出你的意見也:)

謝謝!

+0

你可以使用InvokeScript和一些js來隱藏它嗎? – 2012-07-25 03:02:27

+0

那麼我對編程還是比較新的,所以還沒有真正玩過js。我正在用InvokeScript來查找,但你有什麼建議嗎? – Div 2012-07-25 03:10:35

回答

2

您應該在InvokeScript的頁面注入一個腳本。

以下是你需要刪除後退按鈕樣的Javascript代碼:

// get the first child element of the header 
var backButton = document.getElementsByTagName("header")[0].firstChild; 

// check if it looks like a back button 
if(backButton && backButton.innerText == "Back") { 
    // it looks like a back button, remove it 
    document.getElementsByTagName("header")[0].removeChild[backButton]; 
} 

調用此腳本InvokeScript:

webBrowser1.InvokeScript("eval", "(function() { "+ script +"}()"); 

警告:IsScriptEnabled必須設置爲true在網絡上控制

如果刪除後退按鈕取決於頁面,只需在C#中測試導航URI並注入腳本(如果neeede d。

+0

謝謝!這對我來說就是訣竅:) – Div 2012-07-25 23:03:17

+0

太棒了!別客氣 – 2012-07-26 09:56:42