• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[JS] test selection if hyperlink?

Enthusiast ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Hello,

I try to test if a selection or a result of a search is a hyperlink?

Thank you

Philou

/------------------------------

Bonjour,

je cherche à test si une selection ou un resultat d'une recheche est un hyperlien ?

Merci  à vous

Philou

TOPICS
Scripting

Views

277

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 04, 2021 Feb 04, 2021

Try the following

if(app.selection[0].findHyperlinks () != "")
 alert("Is a hyperlink")
else
 alert("Not a hyperlink")

-Manan 

Votes

Translate

Translate
Community Expert ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Try the following

if(app.selection[0].findHyperlinks () != "")
 alert("Is a hyperlink")
else
 alert("Not a hyperlink")

-Manan 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Hi Manan,

 

That only means there's an (or more) hyperlink(s) in the selection!  😉

 

(^/)  The Jedi

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Isn't that what the OP wanted to know? This is what I understood and tried to answer 😛

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Hi Philou,

do you mean selected text? Or found text? Then work on with Manan's suggestion.

The result of findHyperlinks() is an array of found hyperlinks.

 

However, you have to be careful what exactly is selected or found.

I did not test that, but I could imagine that the same hyperlink can be found more than one time.

Why? Because findHyperlinks() is not a method of superclass Texts, but comes with:

Character | Word | Line | TextColumn | Paragraph | TextStyleRange | InsertionPoint

 

Certainly this point is worth to explore…

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Thank you to all of you,


my problem was the following in a document with underlined text (with 2690 hyperlink) so sertaint was just signed.


I assume that the hyperLink information has been lost.

I had selected the underlined text and checked if the text was indeed a link. I actually came across some "findHyperlinks" command, after some research, Manan confirms the command. Thank you.

here is the script. simple and with probably a lot of things changed ... (a little in a hurry)

---------

Merci à vous tous,

mon probmème était le suivant dans un document avec du texte souligné (avec 2690 hyperlink) donc sertaint etait juste soiligné. je supose que les information d'hyperLink ont été perdu.

Je davais selectioné le textes souligné et verifié si se texte était bien un lien.

Je suis effectivement tombé sur certte commende "findHyperlinks", après quelque recherche, Manan confirme la commade Merci.

voici le script. simple et avec probalement beaucoup de chose à changé (un peu dans l'urgence)

var leDoc = app.activeDocument;

leMain();


function leMain() {

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING; // mise à zero du Find
with (app.findGrepPreferences){

underline = true;
} // fin

var lesRecherche = leDoc.findGrep(true); // True??
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

if (lesRecherche.length == 0) ErrorExit("Pas de resulta de la recherche.", true);
for (var f = 0; f < lesRecherche.length; f++) {
var laRecherche = lesRecherche[f];
try {
var lelien = laRecherche.findHyperlinks()[0]; // possition ou insertion
}

catch (erreur)

{

if(laRecherche.underline == true){
//$.writeln('yes');
laRecherche.underline = true;
laRecherche.underlineColor = app.activeDocument.colors.item("erreur_Lien"); //corr
laRecherche.underlineGapColor = app.activeDocument.swatches.item("None");
laRecherche.underlineGapOverprint = false;
laRecherche.underlineGapTint = 100;
laRecherche.underlineOffset = -3;
laRecherche.underlineOverprint = false;
laRecherche.underlineTint = 100;
laRecherche.underlineWeight = 10;
}
}
}
}

Merci

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

LATEST
 try {

    app.panels.item('$ID/Hyperlinks').visible = false;

  } catch (_) {

  }
//-----------------------------------
// variabnle general

  var leDoc = app.activeDocument;
  
  
  // ICI pour creation de varaible decouleur et de style de caractaires
//----------------------------------

//surFichier ();
//surLivre ();

leMain();


function leMain() { 
      
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;  // mise à zero du Find
        
        
        with (app.findGrepPreferences){
                        
                        underline = true;
                } // fin 
        
        var lesRecherche = leDoc.findGrep(true);  // True??
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;  
      
        if (lesRecherche.length == 0) ErrorExit("Pas de resulta de la recherche.", true);  
        

        
        for (var f = 0; f < lesRecherche.length; f++) {  
           var laRecherche = lesRecherche[f];
           try {

            var lelien = laRecherche.findHyperlinks()[0]; // possition ou insertion
           
            } 
        
        catch (erreur) 
        
        {
        
            //$.writeln (erreur);
        
           // $.writeln ('n\'est pas un lien');
           if(laRecherche.underline == true){
              //$.writeln('yes');
              laRecherche.underline = true;
              laRecherche.underlineColor = app.activeDocument.colors.item("erreur_Lien"); //corr
              laRecherche.underlineGapColor = app.activeDocument.swatches.item("None");
              laRecherche.underlineGapOverprint = false;
              laRecherche.underlineGapTint = 100;
              laRecherche.underlineOffset = -3;
              laRecherche.underlineOverprint = false;
              laRecherche.underlineTint = 100;
              laRecherche.underlineWeight = 10;
              }
              
            }
        }  

       
    }  //

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines