I am trying to customize Robert Scheitlin's identify widget so that so that the identify result shows field value as a hyperlink if the field value is a url.
Here is what I add in the showIdentifyResults module in the widget.js after line 1297 ( I am using widget version 2.7)
content = content + this.resultFormatString.replace('[attribname]', fld).replace('[attribvalue]', value);
/////////customize to create a hyper link for a field if the value is a url. Field value start with http or https
if (value.search("http:") == 0 || value.search("https:") == 0) {
content.replace(value, '<a href="' + value + '">open link</a>');
}
The "content" doesn't change. Anybody has done that before?
Thanks
Helen
Solved! Go to Solution.
Your welcome. Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.
Helen,
When you put in that code, what does the popup show when you click on it? Are you at least seeing the words "open link" in your popup? Or is it something else (like the unclickable hyperlink? Is there a way to verify that the code is working by having it throw that variable into some kind of text to show that "open link" is the correct text and that it has the associated hyperlink with it?
Also, in your logical statement of checking for http: or https:, maybe you could just check for "http" since that would grab both cases and would cut down on any potential logical issues. So, this:
if (value.search("http") == 0) {
content.replace(value, '<a href="' + value + '">open link</a>');
}
Adrian,
I don't see "open link" anywhere in the identify pop up. It doesn't seem to work after the content.replace statement.
Thanks
Helen
Helen,
I have never used "search" I always use indexOf
content = content + this.resultFormatString.replace('[attribname]', fld).replace('[attribvalue]', value);
/////////customize to create a hyper link for a field if the value is a url. Field value start with http or https
if (value.indexOf("http") == 0) {
content.replace(value, "<a href='" + value + "'>open link</a>");
}
Hello Robert,
I have changed from "search" to "replace", it still not working. Any idea?
Thanks
Helen
Helen,
That is not what I said. I said replace search with indexOf
I am sorry, Robert. Typo - I did change search with indexOf. The code still not does anything to replace the url with "open link"
Helen,
It could be a Case issue then try this:
content = content + this.resultFormatString.replace('[attribname]', fld).replace('[attribvalue]', value);
/////////customize to create a hyper link for a field if the value is a url. Field value start with http or https
if (value.toLowerCase().indexOf("http") > -1) {
content.replace(value, "<a href='" + value + "'>open link</a>");
}
Thanks Robert. It is not a case issue. But it is always a good idea to consider the case when compare strings
I am able to see the code is executed in the Chrome debugger. But after the code is executed, the "content" string doesn't change.
So are you sure that you are getting inside the if condition? Maybe try this:
if (value.toLowerCase().indexOf("http") > -1) {
value = "<a href='" + value + "'>open link</a>");
}
content = content + this.resultFormatString.replace('[attribname]', fld).replace('[attribvalue]', value);