It would really be helpful if web addresses could be hyperlinked in weblink, so that the public could click on links that take them to the address in a browser page. Is that going to be an option in version 10?
Question
Question
Hyperlinks in metadata
Answer
change
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig;
to
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([-\w/_\.]*(\?\S+)?)?)?))/ig;
I added the "-" character to the second section of "[\w/_\.]". I tested this successfully but please let me know if you still have problems with it.
https://regex101.com/r/dX2nO4/1
Thanks!
Replies
Ingeborg,
This is one way that you can do this in WebLink (versions 8 & 9). The following basic jQuery code will run through all of the field values in the Metadata section and convert any values that begin with https or http into clickable links.
1. Open up Docview.aspx and add the following script above the ending </body> tag;
<script type="text/javascript"> $('.FieldDisplayValue').each(function(){ var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig; $(this).html($(this).html().replace(rexp, '<a href="$1" title="$2" target="_blank">$1</a>')) }); </script>
2. Save the file and refresh.
You should now be able to click the Metadata fields that contain URLs.
Hope this helps!
Thanks Wes.
I just tried it but I don't seem to see any difference. The pages still work, but no hyperlinks on web addresses. I copied and pasted the code straight into the docview.aspx file just above the ending body tag. is there something I am missing? Do I need to compile something, or make changes in IIS manager or anything like that?
Ingeborg,
There was an error in my code that may be preventing it from working properly. I have updated the original post with the corrected version. The problem is that;
<script language="text/javascript">
should be;
<script type="text/javascript">
Sorry for the error!
Wes, I tried that on my own before you replied, but that doesn't seem to help either. So there is no restart of IIS or something needed on top of this?
Oh hold on. It is showing up in the left hand side if I click on a document. That is at least a definite improvement. Awesome. But, I am guessing I can't get hyperlinks in the columns for each folder / directory?
If I can just have the hyperlink on the left, I can live with that though! Thanks so much!
Ingeborg,
Follow the same instructions above but open the "Browse.aspx" page and use the following code:
<script type="text/javascript"> $('nobr').each(function(){ var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig; $(this).html($(this).html().replace(rexp, '<a href="$1" title="$2" target="_blank">$1</a>')) }); </script>
Sorry to bother you one more time Wes, but I did apply the above text in the Browse.aspx and it will not hyperlink my url fields. Any ideas or place I can look to find more information? I appreciate the time you are spending on this!
Ingeborg,
No worries and could you please attach a screenshot showing the fields that should be hyperlinked? It will help with testing on my end to ensure that you get this working.
Thanks!
Wes Funderberg
In this case it is the URL for the Agenda. But in the future we will have others as well with maps etc. I haven't quite figured out how to change the view depending on which folder someone is browsing yet. Will tackle that next.
Ingeborg,
Ok, now I see the problem and that is the code that I wrote is for WebLink 9 and you are using 8.2. In that case you will need to add this one line of code right after the "<title>" tag in "Browse.aspx"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Save the file and reload the page. I have tested the same in 8.2 and it works.
Awsesome. I'm going to try that now! I appreciate your help more than you know. I guess the last time we upgraded to LF 10 the new version of weblink was not available yet. I will look into upgrading that as well.
Ah, you're my hero! It is working! I am ecstatic. My users are going to be soooo happy! Thanks again.
That's great to hear! Just remember when you go to WebLink 9 you will not need the added Google API script ;-)
Glad I could help!
Wes
Yes I am going to document this just so that I have it all written down for anyone here to see if they need help. Wish I knew more about web stuff. Need to learn, but these little things help me learn, so I appreciate your help!
Hello everyone,
I am having the same issue with a customer that did an upgrade to WebLink 9.0.1.275.
I added <script type="text/javascript">
$('nobr').each(function(){
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([-\w/_\.]*(\?\S+)?)?)?))/ig;
$(this).html($(this).html().replace(rexp, '<a href="$1" title="$2" target="_blank">$1</a>'))
});
</script>
both to the browse.aspx and docview.aspx before the ending body tag (I also made sure the second - was there) and still unable to make it a hyperlink
I got it to work. I was editting the wrong browse and docview files. Thanks!
Wes,
I just noticed that with a link that has a dash - in it, the script will terminate the hyperlink just before that point. I am trying to figure out where in your regular expression I could add to include the dashes if there should be one or many within the URL? If you can see it quicker than I do, can you drop me a reply?
Thanks in advance.
Inky
change
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig;
to
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([-\w/_\.]*(\?\S+)?)?)?))/ig;
I added the "-" character to the second section of "[\w/_\.]". I tested this successfully but please let me know if you still have problems with it.
https://regex101.com/r/dX2nO4/1
Thanks!
Just saw this as I was running out the door. I will try this first thing in the morning. You must be getting tired of me by now ;)
Thanks Wes. That did it! I will go change my documentation. But hopefully Laserfiche will add this to their final version of any new Weblink they put out! thanks for all the hard work you did. I really appreciate it!
No problem Ingeborg and always glad to help!
Hey Wes,
I have Weblink 10.1 and I am having issues with getting the script you provided to work. With the version differences, do you think the element is called something else other than '.FieldDisplayValue'?
Neither one of these scripts are working for me in Weblink 10.1. Do you guys have any suggestions? I want URLs that are listed in the metadata to be clickable hyperlinks.
Blia,
I have quickly updated the code for WebLink 10.1.x. Place the following code right before the </body> tag in DocView.aspx
<!-- custom script --> <script type="text/javascript"> $(document).ready(function() { waitForEl(".fieldPane",addHyperlinks); }); function addHyperlinks(){ $('.fieldPane').each(function(){ var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig; $(this).last().first().html($(this).last().first().html().replace(rexp, '<a href="$1" title="$2" target="_blank">$1</a>')); }); } //https://gist.github.com/chrisjhoughton/7890303 function waitForEl(selector, callback, maxtries = false, interval = 100) { const poller = setInterval(() => { const el = jQuery(selector) const retry = maxtries === false || maxtries-- > 0 if (retry && el.length < 1) return // will try again clearInterval(poller) callback(el || null) }, interval) } </script> <!-- end custom script -->
Wes,
Thank you for doing that. I feel like my code is all over the place as I added another code to change the homeLink href reference to another URL in my DocView.aspx. Neither is working. Would you mind checking what I have because neither is working.
<script>
System.import('doc-viewer-app').catch(function(err){ console.error(err); });
$( document ).ready(function() {
//document.getElementsByClassName("homeLink").href='MYURL';
var x = document.getElementsByClassName("homeLink");
var i;
for (i = 0; i < x.length; i++) {
if(x[i].attributes = 'STR_HOME'){
x[i].href = 'MYURL';
}
}
function(){waitForEl(".fieldPane",addHyperlinks);
});
function addHyperlinks(){
$('.fieldPane').each(function(){
var rexp = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig;
$(this).last().first().html($(this).last().first().html().replace(rexp, '<a href="$1" title="$2" target="_blank">$1</a>'));
});
}
//https://gist.github.com/chrisjhoughton/7890303
function waitForEl(selector, callback, maxtries = false, interval = 100) {
const poller = setInterval(() => {
const el = jQuery(selector)
const retry = maxtries === false || maxtries-- > 0
if (retry && el.length < 1) return // will try again
clearInterval(poller)
callback(el || null)
}, interval)
}
});
</script>
<weblink:CrawlerPreRender ID="CrawlerPreRender" runat="server"></weblink:CrawlerPreRender>
</body>
</html>
Blia,
To make it easier I would highly suggest not adding code to the already <script> sections that are the default of the DocView.aspx page. Add new ones like:
<script> System.import..... </script> <script type="text/javascript"> var x = document.getElements..... </script> <script type="text/javascript"> function..... </script>