Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Mobile Browser for PC

0.00/5 (No votes)
24 May 2013 2  
This is a simple mobile web browser for PC, to view mobile web sites in PC( Windows).

Introduction

This code guides you to change the User Agent in any browser.

This is a simple mobile web browser for PC. To view mobile web sites in PC (Windows):
https://sourceforge.net/projects/mobile-browser/

Background

Mobile version of Browser (Mobile-browser). Browsing like if you're on your Mobile Device supports various USER-AGENTS for browsing like (iPhone, Nokia Windows Phone, Android, Google Chrome, Firefox). This is simple mobile web browser for PC/windows

You can now open any mobile website in PC like Facebook, YouTube. Google, etc. Client/User agents are Android, iOS, iPhone, iPad, Chrome, Firefox, Internet Explorer 7, IE8 WP8, update will be coming soon adding some new user agent, and changing UI & improve performance and remove bugs. Required .NET Framework 3.5 or 4.0  

Screen Shots  

mobile-web-browser-for-pc_SumeetGehimobile-web-browser-for-pc_SumeetGehi

 

Using the Code 

The code is so simple, when we change the user agent the file urlmon.dll works and it change the user interface of any website to their mobile format. Note: Your have to add the following reference to import the DLL file:

System.Runtime.InteropServices; and urlmon.dll  file  
// Created by Sumeet Gehi
// Windows Forms
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// YOU HAVE TO ADD REFERENC
using System.Runtime.InteropServices;
 
namespace MobileBrowser
{
    public partial class Form1 : Form
    { 
        // TO IMPORT DLL FILE
        [DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
 
        private static extern int UrlMkSetSessionOption(int dwOption, 
                  string pBuffer, int dwBufferLength, int dwReserved);
 
        const int URLMON_OPTION_USERAGENT = 0x10000001;
 
        public void ChangeUserAgent(string Agent)
        {
            UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0);
            
        }       
        //Create string for user agents 
        string and_40 = "Mozilla/5.0 (Linux; Android 4.0.4; DROID RAZR Build/6.7" + 
          ".2-180_DHD-16_M4-31) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/";
        string iphone_30 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X;" + 
          " en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
        //  string iphone_60 = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X)
        //          AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B143 Safari/8536.25";
        string ipad = "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit" + 
          "/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3";
        string and_23 = "Mozilla/5.0 (Linux; U; Android 2.2; fr-fr; Desire_A8181 " + 
          "Build/FRF91) App3leWebKit/53.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
        //  string motorola_razr_40="Mozilla/5.0 (Linux; Android 4.0.4; DROID RAZR
        //   Build/6.7.2-180_DHD-16_M4-31) AppleWebKit/535.19
        // (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/";
        //  string htc_23 = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us;
        //    ADR6300 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
        // string chrome_24 = "Mozilla/5.0 (Windows NT 6.1; WOW64)
        //    AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17";
        string chrome_13 = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 " + 
          "(KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1";
        string ie_8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; " + 
          "Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 3.5.30729)";
        //   string ie_10 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
        string ie_10_win8 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone" + 
          " 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)";

Create function for when user hit Enter then navigate to the URL that in TextBox

// Create function for when user hit Enter then navigate to the URL that in TextBox
            
private void TextBoxUrl_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        webBrowser1.Navigate(TextBoxUrl.Text);
        MessageBox.Show("You press Enter");
    }
}

When user click on GO button 

private void toolStrip_GoButton_Click(object sender, EventArgs e)
{	
    try
    {
       if (radioButton1.Checked == true)
        {
            ChangeUserAgent(and_40);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", 
                   null, "User-Agent: {0}" + and_40);
           // TextBoxUrl.Text = webBrowser1.Url.ToString();
            labelurl.Text =Convert.ToString(webBrowser1.Url.AbsolutePath);
            
        }
        else if (radioButton2.Checked == true)
        {
            ChangeUserAgent(and_23);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", 
                   null, "User-Agent: {0}" + and_23);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri);
        }
        else if (radioButton3.Checked == true)
        {
            ChangeUserAgent(iphone_30);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", null, 
                   "User-Agent: {0}" + iphone_30);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri);
        }
        if (radioButton4.Checked == true)
        {
            ChangeUserAgent(ipad);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", 
                 null, "User-Agent: {0}" + ipad);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri);
        }
        else if (radioButton5.Checked == true)
        {
            ChangeUserAgent(chrome_13);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", null, 
                    "User-Agent: {0}" + chrome_13);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri);
            
        }
        else if (radioButton6.Checked == true)
        {
            ChangeUserAgent(ie_8);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", 
                   null, "User-Agent: {0}" + ie_8);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri);
        }
        else if (radioButton_WP8.Checked == true)
        {
            ChangeUserAgent(ie_10_win8);
            webBrowser1.Navigate(TextBoxUrl.Text, "_self", 
                  null, "User-Agent: {0}" + ie_10_win8);
            labelurl.Text = Convert.ToString(webBrowser1.Url.AbsoluteUri)
            
        }
    }
    catch(Exception exce)
    {
        
        MessageBox.Show("have an error occured","Error!");
    }           
}

Other Buttons  

private void toolStrip_FwdButton_Click(object sender, EventArgs e)
{
    webBrowser1.GoForward();
}

private void toolStrip_BackButton_Click(object sender, EventArgs e)
{
    webBrowser1.GoBack();
}
private void toolStrip_RefreshButton_Click(object sender, EventArgs e)
{
      webBrowser1.Refresh();        
}

private void toolStrip_StopButton_Click(object sender, EventArgs e)
{
    webBrowser1.Stop();
}   
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
    Close();
}

Files Include

  • urlmon.dll in bin/
  • size: 1.0mb

This article is only for beginners to how to change User interface (user agent) in any web browser

History   

This is my second article/tip. I know it has many mistakes. I hope to make my next article better than this. 

next update will be coming soon  

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here