Pure JS Settings homepage, add to Favorites, get URL parameters, solve Chinese garbled

Source: Internet
Author: User

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

1. Preface

Pure JavaScript Settings homepage, add to 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 action is 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. ");} 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, follow these steps: 1. Open the browser settings. 2. Click on the Settings page. 3. Enter: "+ VRL +" click OK. ");}}}



3, add to the collection

Favorites compatible with 360 and ie6function Shoucang (Stitle, sURL) {try {window.external.addFavorite (sURL, stitle);} catch (e) {try {window . Sidebar.addpanel (Stitle, sURL, "");} catch (E) {alert ("Failed to bookmark, use Ctrl+d to add");}}

4. Get URL parameters

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

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 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 (when encode is unsuccessful, two times encode is used, so two times decode) $ (" #textfield ") . val (keyword); simplequery (); $ ("#search_paging"). Show ();










 

  





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.