- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ12-14-2023
06:37 AM
Opening external link on FS_BUTTON
Hello,
Does anyone have idea how I can open an external link in a browser using the FS_BUTTON?
Like an onclick event in JS
Thanks
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ01-03-2024
05:11 AM
Hello,
a possible solution:
Insert following class in a fs module:
import de.adesso.firstspirit.template.AbstractExecutable;
import de.espirit.firstspirit.access.BaseContext;
import de.espirit.firstspirit.access.ClientScriptContext;
import de.espirit.firstspirit.agency.OperationAgent;
import de.espirit.firstspirit.webedit.server.ClientScriptOperation;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class OpenUrlInBrowserExecutable extends AbstractExecutable<ClientScriptContext> {
private final String PARAM_URL = "p_url";
@Override
public Object execute(){
String url = getStringFromParameters(PARAM_URL);
//ContentCreator Case
if(context.is(BaseContext.Env.WEBEDIT)){
openWindowWebEdit(url);
}
//SiteArchitect Case
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (URISyntaxException | IOException e) {
context.logError("Could not open URL '" + url + "' !", e);
}
}
return null;
}
private void openWindowWebEdit(String url){
ClientScriptOperation scriptOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(ClientScriptOperation.TYPE);
String script = "window.open('"+url + "','_blank');";
scriptOperation.perform(script, false);
}
}
Create a firstspirit script and insert the executable
<FS_BUTTON name="pt_openUrl_button" hFill="yes" icon="media:question_mark" noBreak="no" onClick="script:sc_openurlinbrowser" style="firstspirit" useLanguages="no"> <LANGINFOS> <LANGINFO lang="*" label="TEXT_FALLBACK" description="TEXT_FALLBACK"/> <LANGINFO lang="DE" label="รffne Link" description="Hilfe"/> <LANGINFO lang="EN" label="Open link" description="Help"/> </LANGINFOS> <PARAMS> <PARAM name="p_url">https://www.adesso.de/</PARAM> </PARAMS> </FS_BUTTON>
hope that helps...
greeting,
Christopher

