Javascript-how to modify all external link forms on an html page?

Source: Internet
Author: User
For example, I have A.comaindex.html, which contains many external links of different websites (such as B .com, c.com, and d.com ). Now I want to use php, JS, or other methods to achieve this. Click the external link "B .com". The address opened in the new window is "a. combindex. php? B. c... for example, I have: http://a.com/a/index.html. There are many external links (such as B .com, c.com, and d.com) on this page ).
Now I want to use php, JS or other methods to achieve, click the external link "B .com", the address opened in the new window is "http://a.com/ B /index.php? B .com.
Thank you. I don't know much about the code. I hope you can give me some advice on how to replace all external links in a unified manner?

Reply content:

For example, if I have: http://a.com/a/index.html, there are many external links (such as B .com, c.com, and d.com) on the page ).
Now I want to use php, JS or other methods to achieve, click the external link "B .com", the address opened in the new window is "http://a.com/ B /index.php? B .com.
Thank you. I don't know much about the code. I hope you can give me some advice on how to replace all external links in a unified manner?

CaptureclickEvent, and then modify it in the event processing functionhref.

$ (Document ). on ('click', 'a: not ([data-bypass]) ', function (e) {var $ target = values (e.tar get), href = $ target. attr ('href '), prefix = 'HTTP: // a.com/ B /index.php? '; If (/^ http :\/\//. test (href) {$ target. attr ('href ', prefix + href);} // mark the checked items and the $ target will not be checked again later. attr ('data-bypass', 'bypass ');});

This approach is followed by direct traversal.ModifyhrefThe advantage is that there is no dead corner and high efficiency.Still valid. In addition, You only need to write in the label firstdata-bypassThis is convenient.

Jquery obtains all A tags and replaces them in batches.hrefIshttp://Starting

$("a[href*='http://']").each(function() {  $(this).attr('href','http://www.fsdeveloper.net'+'/'+$(this).attr('href'));});

Similar to this method,

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.