Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code below should do the trick. Rather than use regex, I used the <a href="http://api.jquery.com/attribute-ends-with-selector/" rel="nofollow">ends with selector</a>. This should serve the same purpose, and execute quicker. Instead of rewriting the tag completely, I just modified the attributes using <a href="http://api.jquery.com/attr/" rel="nofollow">jQuery.attr()</a>. A live example is <a href="http://jsfiddle.net/TjYR6/2/" rel="nofollow">here</a>.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;test&lt;/title&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('a[href$=apk]').each(function() { var mydomain = "http://mydomain2.com?f="; var $this = $(this); $this.attr("href", mydomain+$this.attr("href")); $this.attr("target", "_blank"); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="http://download.domain.com/files/androidfile1.apk"&gt;&lt;img src="theme/download.gif" border=0 alt="download" height="120px" width="130px"&gt;&lt;/a&gt;&lt;br/&gt; &lt;a href="http://download.domain.com/files/androidfile2.apk"&gt;&lt;img src="theme/download.gif" border=0 alt="download" height="120px" width="130px"&gt;&lt;/a&gt;&lt;br/&gt; &lt;a href="http://download.domain.com/files/androidfile3.apk"&gt;&lt;img src="theme/download.gif" border=0 alt="download" height="120px" width="130px"&gt;&lt;/a&gt;&lt;br/&gt; &lt;a href="http://download.domain.com/files/androidfile4.apk"&gt;&lt;img src="theme/download.gif" border=0 alt="download" height="120px" width="130px"&gt;&lt;/a&gt;&lt;br/&gt; &lt;a href="http://download.domain.com/files/androidfile5.apk"&gt;&lt;img src="theme/download.gif" border=0 alt="download" height="120px" width="130px"&gt;&lt;/a&gt;&lt;br/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The resulting output is:</p> <pre><code>&lt;a target="_blank" href="http://mydomain2.com?f=http://download.domain.com/files/androidfile1.apk"&gt;&lt;img src="theme/download.gif" alt="download" height="120px" border="0" width="130px"&gt;&lt;/a&gt;&lt;br&gt; &lt;a target="_blank" href="http://mydomain2.com?f=http://download.domain.com/files/androidfile2.apk"&gt;&lt;img src="theme/download.gif" alt="download" height="120px" border="0" width="130px"&gt;&lt;/a&gt;&lt;br&gt; &lt;a target="_blank" href="http://mydomain2.com?f=http://download.domain.com/files/androidfile3.apk"&gt;&lt;img src="theme/download.gif" alt="download" height="120px" border="0" width="130px"&gt;&lt;/a&gt;&lt;br&gt; &lt;a target="_blank" href="http://mydomain2.com?f=http://download.domain.com/files/androidfile4.apk"&gt;&lt;img src="theme/download.gif" alt="download" height="120px" border="0" width="130px"&gt;&lt;/a&gt;&lt;br&gt; &lt;a target="_blank" href="http://mydomain2.com?f=http://download.domain.com/files/androidfile5.apk"&gt;&lt;img src="theme/download.gif" alt="download" height="120px" border="0" width="130px"&gt;&lt;/a&gt;&lt;br&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload