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?
Captureclick
Event, 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.
Modifyhref
The advantage is that there is no dead corner and high efficiency.
Still valid. In addition
, You only need to write in the label firstdata-bypass
This is convenient.
Jquery obtains all A tags and replaces them in batches.href
Ishttp://
Starting
$("a[href*='http://']").each(function() { $(this).attr('href','http://www.fsdeveloper.net'+'/'+$(this).attr('href'));});
Similar to this method,