I'm using a PDF to HTML plugin for wordpress, which generates a canvas and a text layer for each page. I need to make any URL's click-able within the PDF, so I'm trying to write a script that will detect and URLS (using .com as the identifier, I may add to this later).
all I need help with at this stage is capturing the full URL as a variable, not just the div that contains the ".com"
I currently have this script, however I need to replace "http://test.com" with the URL that is found.
$('div:contains(".com")').each(function () {
$(this).addClass('contains-url');
console.log('found div containing a URL');
$(this).attr('href','http://test.com');
});
$('.contains-url').click(function(){
console.log('clicked - this will open in a new tab');
window.open($(this).attr("href"), '_blank');
});
div{
border: 1px solid #000; padding: 5px; width: 100%; margin-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
This div does not contain a URL
</div>
<div>
This div contains URL http://loremipsum.com
</div>
Any help is much appreciated