Jump to content

Run a href string without click.


cristianotestai

Recommended Posts



Hi,

 

I have a simple function below that returns a href string. How do i run the link returned by the function? I try with AddJS, but without sucess.


 

function GeHref: string;

begin

   Result: = '<a href="mailto:name@host.com"> </a>';

end;


 

procedure UniButtom1Click(Sender: TObject);

var

   link: string;

begin

   link: = GeHref;

   //How do i execute the string returned by the function? 

end;

 

Thanks.

Link to comment
Share on other sites

Hi Cristiano,

 

Well, if I understand correctly you, you always have a string with the tag <a>

 

Then try the following:

procedure UniButtom1Click(Sender: TObject);
var
  link: string;
begin
  link: = GeHref;
  //How do i execute the string returned by the function? 

  link := link.Replace(' ', '');
  link := link.Substring(Pos('href="', link)+5);
  link := Copy(link, 1, Pos('"', link)-1);
  // Or you can use regular expressions

  UniSession.BrowserWindow(link, 0, 0, '_blank');
end;

Best regards.

Link to comment
Share on other sites

Hi Delphi Developer!

Thanks for your answer! It worked almost 100%.

In my case I always return the string with the syntax "mailto:" to open the user's email program. With this, I have three issues to resolve:

1) How do I indicate that it should open a new folder and not a new window?

2) In Chrome, the URL open in new window is showing all the contents of the string mailto, which should show _blank only. In Firefox it is ok. Any idea?

3) The third issue I think is the most difficult. I wanted to identify if the user uses a standard desktop email program such as Windows Live, Thunderbird, or any other. If use, just run the "mailto" URL without opening new folder or new window, in which case it will open the default e-mail program, no need to create new window.

Thanks for your help!

 

Best Regards,

 

Cristiano

Link to comment
Share on other sites

The only way is to actually force user to click the link, this is a security measure in browsers to prevent sites from launching associated apps themselves. the same way as browsers asking you what to do with downloaded file instead of launching associated apps on their own.

 

If your mailto address depends on lets say the selected row in dbgrid, update UniLabel link in AfterScroll event.

Link to comment
Share on other sites

Hi zilav, 

 
In my app, the user query and selects in the grid which customers want to send email.
With selected records, he click on a button that internal search all selected records and create the string with the syntax "mailto" with all emails.
 
In this case, it must be executed on return of this function, without user intervention, as are several emails indicated in the mailto syntax.
 
Thanks for help.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...