Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It might just be cleaner to write the code yourself. Try the following:</p> <pre><code>// Grab every &lt;a&gt; tag in the document. var allTheTags = document.getElementsByTagName('a'); function parseTags(tags) { var size = tags.length; // cache the size; for (var i = 0; i &lt; size; i++) { var tag = tags[i]; var href = tag.getAttribute('href'); // Do we have a target attribute? (and, of course, an href attribute) if (href &amp;&amp; !tag.getAttribute('target')) { var ourHostName = window.location.hostname; href = href.split('://'); // Is there a protocol? if (href.length &gt; 1) { href = href[1].split('/')[0]; // Get everything before the first / if (href != window.location.hostname &amp;&amp; href != 'www' + window.location.hostname) { // Sometimes, hostname does not have www in it. tag.setAttribute('target', '_blank'); } } } } }; // Call our function. parseTags(allTheTags); </code></pre> <p>Our variable "allTheTags" is a Nodelist, which will update when the DOM updates, so we can always re-run our parseTags function passing in our allTheTags object each time. This way, we skip querying the DOM if there's an instance where a tags are added dynamically.</p> <p><strong>EDIT</strong></p> <p>In the case of accounting for poproll functionality, you'll have to listen for the same roll-over event you pass to your poproll function. So, right after you call poproll on the element you selected, listen for a hover on that same element.</p> <pre><code>$(someElementYouUseForPoproll).hover(function () { parseTags(allTheTags); }, function() { }); </code></pre> <p>This way, after our markup has been injected, this hover event is next in-line to be executed and will now see the tag the poproll generated in the DOM.</p>
 

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