Use JS to dynamically modify the url to add, query, modify, and delete the url.

Source: Internet
Author: User

Use JS to dynamically modify the url to add, query, modify, and delete the url.

Although you can modify the url dynamically by submitting a post form using the get method, if multiple buttons can be submitted in parallel, write multiple forms with the same details and differences, it is inevitable that there is something wrong. Therefore, I thought of using JS to dynamically modify the url to add, query, modify, and delete the url.

<Script> var LG = (function (lg) {var objURL = function (url) {this. ourl = url | window. location. href; this. href = "";//? Previous section this. params = {}; // url parameter object this. jing = ""; // # And this. init ();} // analyze the url? Save this. href. The parameter is resolved to this. params object, # And save it to this. jing objURL. prototype. init = function () {var str = this. ourl; var index = str. indexOf ("#"); if (index> 0) {this. jing = str. substr (index); str = str. substring (0, index);} index = str. indexOf ("? "); If (index> 0) {this. href = str. substring (0, index); str = str. substr (index + 1); var parts = str. split ("&"); for (var I = 0; I <parts. length; I ++) {var kv = parts [I]. split ("="); this. params [kv [0] = kv [1] ;}} else {this. href = this. ourl; this. params = {};}// only modify this. params objURL. prototype. set = function (key, val) {this. params [key] = val;} // only sets this. params objURL. prototype. remove = function (key) {this. params [key] = undef Ined;} // The url objURL after the three-part operation. prototype. url = function () {var strurl = this. href; var objps = []; // The array is used here, And the join operation for (var k in this. params) {if (this. params [k]) {objps. push (k + "=" + this. params [k]) ;}} if (objps. length> 0) {strurl + = "? "+ Objps. join ("&");} if (this. jing. length> 0) {strurl + = this. jing;} return strurl;} // obtain the parameter value objURL. prototype. get = function (key) {return this. params [key];} lg. URL = objURL; return lg ;}( LG ||{}); var myurl = new LG. URL (window. location. href); myurl. remove ("B"); // Delete B alert (myurl. get ("a"); // obtain the value of parameter a. Here, 1 myurl is obtained. set ("a", 23); // modify the value of a to 23 alert (myurl. url (); </script>


JavaScript to implement dynamic URLs

Adding javascript scripts in href does not work. Dynamic URLs can be implemented only when a function is called by triggering an event. Below is an implementation method.
<Script language = "javascript">
Var tempUrl = "";
Function addText (obj ){
TempUrl = obj. href;
Obj. href + = obj. innerText;
}
Function delText (obj ){
Obj. href = tempUrl;
}
</Script>

<A href = "www.abc.com #" onmouseover = "addText (this)" onmouseout = "delText (this)">
Link text
</A>

If the URL is known, how can I download the URL in byte stream format using js or HTTP protocol change?


 

Related Article

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.