在ASP.NET網頁中加入MSN字典,Yahoo字典,Google搜尋,Yahoo知識+

看到puma大的這一篇(利用ASP.NET做一個結合Microsoft與Google翻譯網頁的小工具 ),剛好可以把他加入小喵自己平時工作電腦的首頁中。
不過小喵稍稍的修改了一下用法,小喵結合的字典是【MSN的側邊字典】,【Yahoo字典】,【InfoSeek日英字典】,【Google搜尋】與【Yahoo知識+】。

看到puma大的這一篇(利用ASP.NET做一個結合Microsoft與Google翻譯網頁的小工具 ),剛好可以把他加入小喵自己平時工作電腦的首頁中。

不過小喵稍稍的修改了一下用法,小喵結合的字典是【MSN的側邊字典】與【Yahoo字典】。使用MSN側邊字典的原因是,剛好他提供的側邊字典的寬度剛好可以放入小喵的首頁中,相關程式碼如下:

補充:後來小喵再次做調整,增加了【InfoSeek日英字典】、【Google搜尋】與【Yahoo知識+】,如果有需要的人可以自己在加上自己常用的搜尋。

畫面的部分:
小喵以Div裡面放iframe的方式呈現結果。另外透過重疊的Div做出類似視窗的視覺效果。

<asp:DropDownList ID="ddlDictSrc" runat="server"> 
    <asp:ListItem Value="MCE">(字典)MSN字典(繁英)</asp:ListItem> 
    <asp:ListItem Value="YahooCE">(字典)Yahoo(繁英)</asp:ListItem> 
    <asp:ListItem Value="IJE">(字典)InfoSeek(和英)</asp:ListItem> 
    <asp:ListItem Value="YKM">(搜尋)知識+</asp:ListItem> 
    <asp:ListItem Value="Google">(搜尋)Google</asp:ListItem> 
</asp:DropDownList> 
<asp:TextBox ID="txtWord" runat="server"></asp:TextBox> 
<asp:Button ID="btnStartDict" runat="server" Text="翻譯/搜尋" /> 
<div id="divDict" runat="server" visible="false"> 
    <div style="position:absolute; width: 640px; height: 480px; top: 90px; left: 50px; background-color: #333333;"></div> 
    <div style="position:absolute; width: 640px; height: 480px; top: 70px; left: 30px; background-color: #FFCC99;"> 
        <div style="background-color:#800000; color:White; text-align: center;"> 
            字典/搜尋 
            <asp:Button ID="btnClsDict" runat="server" Text="關閉" /> 
        </div> 
        <iframe id="ifrmDict" name="ifrmDict" runat="server" width="640px" height="460px"></iframe> 
    </div> 
</div>

CodeFile的部分:

    '微軟翻譯網址 
    Dim MUrl As String = "http://dic.lifestyle.msn.com.tw/dict/word?k=" 
    'Yahoo翻譯網址 
    Dim YUrl As String = "http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=" 
    'InfoSeek翻譯網址 
    Dim IUrl As String = "http://dictionary.www.infoseek.co.jp/?spa=1&sc=1&se=on&lp=0&gr=ml&qt=@@sWord&sm=1&sv=2T" 
    'Yahoo知識+網址 
    Dim YKMUrl As String = "http://tw.search.yahoo.com/search/kp?fr=sfp&ei=UTF-8&p=" 
    'Google搜尋 
    Dim GoogleUrl As String = "http://www.google.com.tw/search?hl=zh-TW&q=@@sWord&meta=&aq=f" 

    '最後網址 
    Dim Url As String = "" 

    '要翻譯的文字 
    Dim sWord As String = Server.UrlEncode(Me.txtWord.Text) 

    Select Case Me.ddlDictSrc.SelectedValue 
        Case "MCE" 
            Url = MUrl & sWord 

        Case "YahooCE" 
            Url = YUrl & sWord 

        Case "IJE" 
            Url = Replace(IUrl, "@@sWord", sWord) 

        Case "YKM" 
            Url = YKMUrl & sWord 

        Case "Google" 
            Url = Replace(GoogleUrl, "@@sWord", sWord) 

    End Select 
    Me.divDict.Visible = True 
    Me.ifrmDict.Attributes.Add("src", Url) 
End Sub

執行結果如下:圖片點擊放大

條件輸入:Yahoo字典,搜尋NDS
  

搜尋結果:

條件改為Yahoo知識+,結果:

 


以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat