Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

c# - Windows Mobile 6.5 Professional

I have a problem with windows mobile 6.5 professional. Developed an application that runs on windows mobile 6.5 classic, opening a website from webbrowser. In Professional website works correctly in IE, but not working javascript / jquery in my application with webbrowser. I found it strange the contents of the request agent (Request.UserAgent) from the Professional: Mozilla/4.0 (compatible, MSIE 6.0, Windows CE; IEMobile 7:11)

When the Classic appears the following result:

Mozilla/4.0 (compatible, MSIE 6.0, Windows NT 5.1, Windows Phone 6.5.3.5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I recently stumbled upon the same issue. JavaScript works in IE but not in my C# webbrowser component.

The solution was to check HKLMSecurityInternet ExplorerMSHTML registry key. It must be 0 to allow javascript inside webbrowser! Now my code checks and changes this reg key to zero (if not alreday 0) and then calls InitializeComponents().

The key will change the behaviour of the webbrowser in another way too: the arrow keys now do not move the focus from link to link but they scroll the webbrowser view.

Hope that helps you too.

EDIT: here is a code sample:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WebBrowser
{
    public partial class Form1 : Form
    {

    public Form1()
    {
        checkMSHTML(0);
        InitializeComponent();
        webBrowser1.ScriptErrorsSuppressed = false;
    }

    private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
    {
        switch (e.Button.ImageIndex)
        {
            case 0:
                webBrowser1.Url = new Uri( "http://192.168.128.5/www");
                break;
            case 1:
                this.Close();
                break;
        }

    }

    /// <summary>
    /// check and change MSHTML rendering engine
    /// </summary>
    /// <param name="iVal">0 = use new IE6 engine, enable JavaScript
    /// 1 = use old PIE engine</param>
    /// <returns></returns>
    bool checkMSHTML(int iVal)
    {
        bool bRet = false;
        Microsoft.Win32.RegistryKey rKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SecurityInternet Explorer",true);
        if (rKey != null)
        {
            int iMSHTML = (int) rKey.GetValue("MSHTML");
            if (iMSHTML != iVal)
            {
                rKey.SetValue("MSHTML", iVal, Microsoft.Win32.RegistryValueKind.DWord);
                rKey.Flush();
                rKey.Close();
                bRet = true;
            }
            else
            {
                rKey.Close();
                bRet = true;
            }
        }
        return bRet;
    }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...