• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 95
  • Last Modified:

Set one url as the default url of the browser

Hi,
I want to set one given url, as the default url on the relevant machine, once the user has clicked the button, on the webpage, within either IE browser or Chrome browser. Must this be done through Javascript? If yes, any example/demonstration to this?
0
HuaMinChen
Asked:
HuaMinChen
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
I found this by googling... I'm on the phone so I can't test it.

<script language="javascript">
function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.asp.net/130.aspx');
 

    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         }
         catch(e)
         {
    alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
         }
    }
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://www.asp.net/130.aspx');
 }
}
</script>
<input type="button" value="set home page" onclick="setHomepage();" />

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to start with: there's no universal support, it's different for every browser (if they actually support it)
Also, suggesting to change the homepage is generally considered a very annoying to me as end-user, as all the browsers happen to have in their menu (set current page as home page), and as network admin this will be blocked and/or overridden in most secured networks anyhow.

you can find tons of examples in the internet and EE, searching for setting home page in the brower...
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Alexandre,
using these codes
    <script type="text/javascript">
        function setHomepage() {
            if (document.all) {
                document.body.style.behavior = 'url(#default#homepage)';
                document.body.setHomePage('http://www.asp.net/130.aspx');
            }
            else if (window.sidebar) {
                if (window.netscape) {
                    try {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                    }
                    catch (e) {
                        alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
                    }
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', 'http://www.asp.net/130.aspx');
            }
        }
    </script>
    ...
            <asp:LinkButton ID="lb_sethome" 
               Text = "Set this as Home"
               CssClass="lb_sethome"
               Font-Names="Times New Roman" 
               Forecolor="#0A2757"
               Font-Size="8pt" 
               OnClick="setHomepage();" 
               runat="server"/>
               ...

Open in new window

I get this error
Server Error in '/App11' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1026: ) expected

Source Error:


Line 90:         <tr>
Line 91:             <td align="right" style="ForeColor:#0A2757;">
Line 92:             <asp:LinkButton ID="lb_sethome" 
Line 93:                Text = "Set this as Home"
Line 94:                CssClass="lb_sethome"

Source File: c:\inetpub\VS2012\App11\Default.aspx    Line: 92 


Show Detailed Compiler Output:


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now