Jump to content

href link on TUniHTMLFrame


edbuescher

Recommended Posts

I have a TUniHTMLFrame where I've placed some links like

<a href="../DataPage">Click Here</a>

I can capture the link in the ServerModule's OnHTTPCommand or in the Main Form OnShow or OnActivate methods.

The problem is that the link is spawning a new session.  How do I achieve putting a link on a TUniHTMLFrame, but have it come back in the same session? I assume this would be done with something like an Ajax call, but I don't know how to do this.  I've looked at various forum posts for REST calls and OnHTTPCommand processing, but I'm still at a loss.

Thanks for any help

Link to comment
Share on other sites

I have these html links on a TUniHTMLFrame which is on a TUniForm. These links are simply html text on the frame, not part of a grid/table.  I want to be able to click on one of the links and have it open a new form within the current application, not launch a new instance of the application, which is what it is doing now. I have another form with a TUniDBGrid and one of the columns has widget buttons, and I have the button click coded to open a new form within the application. I want to achieve similar functionality with a <a href=...> link displayed on an HTMLFrame. 

Let's say you had a form that had an "About Us" or "Contacts" link (formatted as an html <a href..> link) in the footer at the bottom of pages, and if a user clicked on the link you would want to open another form within the application. How would you do this?

Link to comment
Share on other sites

2 hours ago, Sherzod said:

Can you use UniHTMLMemo?

 

I just tested by replacing the TUniHTMLFrame with a TUnitHTMLMemo. The <a href...> links display properly (as HTML Links), but don't act like links, that is the mouse doesn't change when you hover over the link text, and nothing happens if you click it. Am I missing something here?

Link to comment
Share on other sites

It is very easy to generate an Ajax call from an Anchor element, by using the onclick event:

<a onclick="ajaxRequest(MainForm.HTMLFrame, ['linkclicked'], {  link: 'test'});">A link</a>

In the MainForm you respond to the call, and open whichever form you wish:

procedure TMainForm.HTMLFrameAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if sameText(eventname,'linkclicked') then
  begin
    showMessage('Link clicked: '+Params.Values['link']);
  end;
end;

A test project is attached.

ajaxtest.zip

Link to comment
Share on other sites

21 hours ago, Ron said:

It is very easy to generate an Ajax call from an Anchor element, by using the onclick event:

<a onclick="ajaxRequest(MainForm.HTMLFrame, ['linkclicked'], {  link: 'test'});">A link</a>

In the MainForm you respond to the call, and open whichever form you wish:

procedure TMainForm.HTMLFrameAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if sameText(eventname,'linkclicked') then
  begin
    showMessage('Link clicked: '+Params.Values['link']);
  end;
end;

A test project is attached.

ajaxtest.zip 54.42 kB · 2 downloads

 

Ron, Thank you so much for the sample code and project. I tested it and it indeed works. I'll end up using something with an <a href= tag as it shows the link text as a link and the mouse cursor changes when you hover over the link, but your code will work great in other situations where I don't need that, such as clicking on a picture.

 

Link to comment
Share on other sites

On 1/26/2022 at 12:21 PM, Sherzod said:

Set it to read only, and search the forum, there is a solution to your question.

Here is the link I found and used with success

I am able to grab and process the ajax callback but now I have another issue to deal with.

The link is embedded in a UniHTMLMemo.

How do I resolve the issue of the UniHTMLMemo only showing "true" after the click on the link:

Before Click:
image.png.ce9ac4072c03a0cb86eb2c59af19709a.png

Then after I click a link the form clears and the UniHTMLMemo shows "true"

image.png.bd3ac1538e2787eb01b92a46f1ffd95a.png

This happens BEFORE I capture the Ajax call which looks like this on the client
javascript:window.parent.ajaxRequest(window.parent.O3B7, 'hrefClickAvg', ['hrefId=80106090(TX)'])

Thanks for any help

Link to comment
Share on other sites

Of course you can add an href tag for identification, but that is not necessary as you have the ability to identify the link through the ajax call using a parameter, as in the example. As you have to use a parameter anyway, you might as well use the parameter itself as the identifier, rather than using the href and then passing the href as a parameter, if you understand what I mean. Keep it simple. You will probably generate the html code automatically, so you can do this the way you like.

Regarding your issue with the memo, you need to attach a test project for us to be able to analyze what happens.

 

Link to comment
Share on other sites

Here's a test project that shows a UniHTMLMemo with 3 href links. When you click on a link it opens another form, and the text in the UniHTMLMemo, where the links are, now shows "True" until you close the form that was launched, then the links reappear. Ultimately I'd like to give the user the ability to open several of the links, but they can't because they disappear after you click the 1st link.

TestLink.zip

Link to comment
Share on other sites

On 1/26/2022 at 12:21 PM, Sherzod said:

Set it to read only, and search the forum, there is a solution to your question.

Sherzod, could you take a look at the test app I wrote to see if you can tell why it's acting the way it is.  I'd really appreciate it as I'm stumped.

Thanks,

Eric

Link to comment
Share on other sites

On 2/5/2022 at 2:53 AM, edbuescher said:

Here's a test project that shows a UniHTMLMemo with 3 href links. When you click on a link it opens another form, and the text in the UniHTMLMemo, where the links are, now shows "True" until you close the form that was launched, then the links reappear. Ultimately I'd like to give the user the ability to open several of the links, but they can't because they disappear after you click the 1st link.

Hello,

Sorry, I don't really understand what you want.

Link to comment
Share on other sites

  • 1 month later...
On 2/10/2022 at 3:14 PM, edbuescher said:

On my system when you click on one of the <a href> links, the text in the UniHTMLMemo, where the links are, gets cleared and replaced with "True". Does it not do that on your system? If you look at my post from January 27, you will see some screenshots.

Sherzod,

I'm getting desperate here. I've sent support emails and have messaged you and Farshad, but haven't received any response in weeks, yet I can see UniGui has put out a new release and you are responding to other forum threads.

I could really use some help. If you are stumped with my situation, could you have someone reply to my support email on this (FSD-4426). I'd really appreciate it.

Thanks

Link to comment
Share on other sites

Thank you for responding.  Were you able to run the test app I sent on January 4th?  It shows a UniHTMLMemo with embedded html links in the syntax of <a href>...</a>. Let's say that UniHTMLMemo is on Form A. The Ajax event captures the click on the link and opens Form B, but before it does so, Form A (or the UniHTMLMemo) is blanked and only shows the text "true". I have screen shots in my post from January 27.  In my Test App, as soon as I close Form B, then Form A refreshes automatically and shows the original content, but in my production app, Form A continues to show "true".

So If you have any idea on how to fix this, I'd love to know. If not, could you have someone respond to my support email (FS-4426).  I also need to renew my annual license, but was unwilling to do so since nobody was responding to my emails regarding this. I was wondering if you all were still around, so THANK YOU for responding.

Eric

Link to comment
Share on other sites

1 hour ago, edbuescher said:

Thank you for responding.  Were you able to run the test app I sent on January 4th?  It shows a UniHTMLMemo with embedded html links in the syntax of <a href>...</a>. Let's say that UniHTMLMemo is on Form A. The Ajax event captures the click on the link and opens Form B, but before it does so, Form A (or the UniHTMLMemo) is blanked and only shows the text "true". I have screen shots in my post from January 27.  In my Test App, as soon as I close Form B, then Form A refreshes automatically and shows the original content, but in my production app, Form A continues to show "true".

So If you have any idea on how to fix this, I'd love to know. If not, could you have someone respond to my support email (FS-4426).  I also need to renew my annual license, but was unwilling to do so since nobody was responding to my emails regarding this. I was wondering if you all were still around, so THANK YOU for responding.

Eric

Sherzod,

Also, here is what the links look like

The link code in a uniHTMLMemo : <a href="javascript:window.parent.ajaxRequest(window.parent.O3C0, ''hrefClickAvg'', [''hrefId=80076078(TX)''])">80076078</a>

and when you hover over the link it renders as: javascript:window.parent.ajaxRequest(window.parent.O3C0, 'hrefClickAvg', ['hrefId=80076078(TX)'])

when you click on the link, the entire form (or maybe it's just the uniHTMLMemo) is blanked then renders the text "true", and then I can capture the AjaxEvent to handle the link request, so I'm fairly sure the issue is on the client side.  Maybe there's a better way to render html links, or dynamically create widget type buttons instead of using links, although I'd still like to know how to get this working if possible.

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...