Identify widget display field value as a hyperlink

1080
13
Jump to solution
09-13-2018 02:53 PM
HelenZhou
Occasional Contributor II

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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.

View solution in original post

0 Kudos
13 Replies
AdrianWelsh
MVP Honored Contributor

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>');

      }

0 Kudos
HelenZhou
Occasional Contributor II

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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>");
    }‍‍‍‍‍
0 Kudos
HelenZhou
Occasional Contributor II

Hello Robert,

I have changed from "search" to "replace", it still not working. Any idea?

Thanks

Helen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   That is not what I said. I said replace search with indexOf

0 Kudos
HelenZhou
Occasional Contributor II

I am sorry, Robert. Typo -  I did change search with indexOf. The code still not does anything to replace the url with "open link"

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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>");
    }
0 Kudos
HelenZhou
Occasional Contributor II

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.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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);
    
0 Kudos