hi,
in a grid I need to open two tabs with two different urls with an ajax event on click.
help me please
You can make it work in a control form using javascript methods and sc_ajax_javascript macro, but that doesn’t apply to a grid application. The closest I could come was to create a javascript button (at the top of the grid in the toolbar) that opens two windows in two new tabs.
To do that, create a button and in the Javascript Code put:
window.open(“https://url1.com”);
window.open(“https://url2.com”);
If you need the two URLs to be opened on the click of a specific record I haven’t found a way to do that.
EDIT:
Posted too soon. I found a way if you need to pass parameters from each record or change the URLs based on the row data.
For example, if a field1 value on the row == “A” I will open google.com and bing.com. If the field1 value is !==“A” then I open reddit.com and twitter.com when the user clicks on ‘myfield’.
In the myfield_onClick event:
if ({field1} == 'A')
{
[glo_url1] = "https://www.google.com";
[glo_url2] = "https://www.bing.com";
}
else
{
[glo_url1] = "https://www.reddit.com";
[glo_url2] = "https://www.twitter.com";
}
sc_redir("blank_app_with_script",,"_blank");
This will open the blank_app_with_script in a new tab, leaving the original grid open.
Create a blank app (called “blank_app_with_script” in this example) and in the onExecute event of that application put the following:
$URL1 = [glo_url1];
$URL2 = [glo_url2];
?>
<script type="text/JavaScript">
window.onload = function open2() {
window.open("<?echo ($URL2);?>", "_blank");
window.open("<?echo($URL1);?>", "_self");
}
</script>
<?
This will open URL2 in a new tab, then open URL1 in the tab that loaded “blank_app_with_script”
Tested and working for me in Chrome under SC 9.8 in development environment.
I was also trying with the controlform open in modal and closed after the opening of the urls, but the solution of the blank app seems better to me.
thank you