Pure JS Set homepage, add favorites, get URL parameters, solve Chinese garbled

Source: Internet
Author: User

Snow Studios copyright All, reprint please specify "http://blog.csdn.net/lina791211"

1. Preface

Pure JavaScript Settings homepage, add favorites.

2. Set Homepage

Set as Home function Sethome (obj, vrl) {try {obj.style.behavior = ' url (#default #homepage) '; Obj.sethomepage (VRL);} catch (E) {if (Window.netscape) {try {netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");} catch (e) { Alert ("This operation was rejected by the browser. \ n Please enter "About:config" in the browser address bar and return to \ n then set the value of [Signed.applets.codebase_principal_support] to ' true ' and double click on it. ");} var prefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice ( Components.interfaces.nsIPrefBranch);p refs.setcharpref (' Browser.startup.homepage ', VRL);} else {alert ("Your browser does not support this, follow these steps: 1. Open the browser settings.

2. Click on the Settings page.

3. Enter: "+ VRL +" click OK. ");}}}



3. Add a collection

Add Favorites compatible 360 and Ie6function Shoucang (Stitle, sURL) {try {window.external.addFavorite (sURL, stitle);} catch (e) {try {window . Sidebar.addpanel (Stitle, sURL, "");} catch (E) {alert ("Add collection failed. Please use Ctrl+d to add ");}}}

4. Get URL parameters

function Geturlparam (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");//Constructs a regular table object with target parameters var r = Window.location.search.substr (1). Match (REG); Match Target parameter if (r! = null) return unescape (r[2]); return null; Returns the number of references}

5, solve the Chinese garbled

Send the Post page $ (' #simpleSearchButton '). Click (function () {var _k = $ (' #textfield '). Val (); var url = "; if (_k==null | | _k==" ") {//url = encodeURI (' <%=path%>/'); return;} Else{url = encodeURI (' <%=path%>/search.jsp?

Keyword= ' + _k);} url = encodeURI (URL);//<span style= "font-family:arial;" > Two encryption (encode may not succeed, use two times encode) </span>window.open (URL, ' _self ');});


Accept the Parameters page//Use the method provided in section fourth window.onload = function () {var keyword = geturlparam (' keyword ');//get keyif (keyword = = null) keyword = "; keyword = decodeURI (decodeuri (keyword));//Two decryption (once encode is unsuccessful.) Use two times encode. So here it's going to be two times decode) $ ("#textfield"). val (keyword); simplequery (); $ ("#search_paging"). Show ();










 

  





Pure JS Set homepage, add favorites, get URL parameters, solve Chinese garbled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.