Solved

Set one url as the default url of the browser

Posted on 2014-12-14
3
65 Views
Last Modified: 2015-09-10
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
Comment
Question by:HuaMinChen
3 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
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
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now