How to access a hidden link in the popup screen and click it using javascript

Hi All

How to access a hidden link in the popup screen using javascript ? I am using RunJavascript action in  from httpRequestHandler extension and trying to click the link using the below script. Its not working.

SyntaxEditor Code Snippet

"$(""#" + link.id + """).click()"

Thanks

KJ

Put the link.id in GetElementById():

Something like:

"GetElementById(" + link.id+ ").Click()"

Hi Karthik,


try 


"$(""#" + link.id + """)[0].click()"


don't know why, just found this on a jquery stackoverflow question


good luck,

Dorine



also make sure to use css class hidden, not parameter visible

Karthik, 

Don't see any problem in your Javascript per se. And I used this a lot of times already. 

How are you 'hiding' the link? 

Cheers

Hi Karthik,

Does your Javascript work if you run it in your browser console?

I believe this is happening because Outsystems popups are rendered inside an iframe, and you can't access elements if you're trying to do so from outside of that iframe.

Do you need to run this Javascript in a server action? Could you try moving this to the popup page, and then controlling it with an If?

Eduardo Jauch wrote:

Karthik, 

Don't see any problem in your Javascript per se. And I used this a lot of times already. 

How are you 'hiding' the link? 

Cheers

Thanks Eduardo, I initially hide it by placing it in true part of the if block by setting the condition "false". Later, I made it visible by removing the if block, but still facing the same issue. 

It is working fine in a webpage. But the issue exist only when i try it in a popup window. 


Hi Karthik,

In the first case, it would not work. When in an IF, if the condition is not met, the element is not built into the HTML. So the link would not be there.

Another question, before anything else.

What is set in the Method of the button/Link that calls the Screen Action that executes the JavaScript?
If it is set to Submit, I think you may have a problem, as when the RunJavaScript runs, it will use the actual ID of the link, but before it is sent back to the browser, the preparation will run and the page will be rebuilt, including the link, changing its ID. I think the JavaScript will have the old ID.

If you are using Submit, try to change to Ajax Submit.

I'll do a small test anyway.

Cheers.

Hi All,


see attached demo, code as Karthik used in initial post doesn't work, clicking on first element in array (as mentioned above) does work, also clicking on the text inside the link does work.


Dorine


Hi,

I've made a test right now and it's working.

How are you hidding the link? With Visible = False it doesn't work, the link should be inside a container with Display = False.

Regards

Solution

Hi, just a few points.

1. If your hidden link, inside the Popup, is calling a Screen Action, the code just works, no matter if the method is submit or ajax, no need to use [0]

2. If your hidden link, inside the popup, is navigating to a page, then it will work ONLY if the screen action executing the RunJavaScript is executed using AJAX, and, for my surprise, but found by Dorine, using the [0].

This last one is very weird, as the link seems to be pretty normal.

I'll investigate.

P.S.: Khartik, it is not usual to navigate to a different page inside a Popup.

Solution

Ok, doing some tests and a little search, found the reason.

The explanation can be found here: https://stackoverflow.com/questions/7183704/jquery-id-selector-id-returns-array

This is a JQUERY thing, it seems.

If you use 'pure JavaScript', like getElementById, as suggested above, it will work on any case.

Cheers.