Function GetClipboardText losing formatting

For example, if I do a toolbar Copy and manually paste into a email, it formats fine:

1976 Cleveland Indians At 1976 Oakland Athletics 4/8/1976
Indians… 0 0 1 0 0 0 0 0 0 - 1 7 0
Athletics… 1 0 1 0 0 1 0 0 x - 3 6 0

But if I do a GetClipboardText to store into a variable and call the email client, the clipboard formatting is lost:

1976 Cleveland Indians At 1976 Oakland Athletics 4/8/1976 Indians… 0 0 1 0 0 0 0 0 0 - 1 7 0Athletics… 1 0 1 0 0 1 0 0 x - 3 6 0

procedure AutoSendMail;
Var
B: String;
S: String;
M: String;
begin
NavigateCommand(4); // Select All
NavigateCommand(3); // Copy
S := “mailto:?body=”;
B := GetClipboardText();
M := S+B;
OpenFile(M, “”, SW_SHOWNORMAL);
end;

Do you mean the CRLF characters are not appropriate?

Yes, they look to be removed or ignored.

Anyway, GetClipboardText uses a Windows API to return the raw text from the clipboard. Maybe CRLF chars are removed by the API.

Is there an alternative to GetClipboardText() to store clipboard data to a variable which will keep CRLF?

I was trying to find an alternative by calling a javascript function to get the clipboard instead of GetClipboardText(). But the ExecuteHTMLScript does not work. Why is that? Not sure what to use as the second parameter.

The HTML javascript (added alerts for testing):
function getClipboard() {
alert(“Starting getClipboard”);
var selection = window.getSelection().toString();
alert(selection);
}

The UserMain procedure;
procedure AutoSendMail;
begin
NavigateCommand(4); // Select All
NavigateCommand(3); // Copy
MessageBox(“running AutoSendMail”,“Title”,MB_OK);
ExecuteHTMLScript(“GetClipboard()”,"");
end;

In the end, the idea is for the javascript to get the clipboard and open the email client and paste the clipboard data into the email body. I took that code out, for now, for test.

Take a look at our demo or documentation for ExecuteHTMLScript. It lets you run JS code. 2nd parameter is the URL for the JS context.

The link on your documentation PHP SAMPLES page fails:

https://www.exeoutput.com/help/php-samples

Please refer to the General Demonstration for demonstrations and PHP samples.

I’ve tried many ways to avoid using GetClipboardText(). But cannot find a solution.

I did a ExeOutput procedure to select the data, then called a JavaScript function to get the data from the clipboard via

var selection = window.getSelection().toString();

On localhost, all works fine and the clipboard data has its CRLF values and the entire clipboard.

The next thing in the JavaScript code was to call the email client. But no matter what I do, all the following fail:

window.location.href = ‘mailto:[email protected]’;

window.location.assign = ‘mailto:[email protected]’;

window.event.returnValue = false;
window.location.assign = ‘mailto:[email protected]’;

setTimeout(function(){document.location.href = ‘mailto:[email protected]’},500);

window.location.assign = ‘mailto:[email protected]’;
return false;

window.location = ‘mailto:[email protected]’;

window.location = ‘http://www.google.com/’;
window.location.href = ‘mailto:[email protected]’;

Then I saw this in a ExeOutput post: “With Chromium, we don’t have the same ability to manage window properties from code.” So I figure I cannot use JavaScript to call mailto. I will, instead, call an ExeOutput procedure, sending the collected clipboard and have it do the email client call. It worked, except one problem…

var selection = window.getSelection().toString();

when compiled and executed under ExeOutput, it only collects about 30 chars from the clipboard.

I’m in a quandary. GetClipboardText() removes CRLF, and under ExeOutput window.getSelection().toString(); fails to get all the clipboard data.

What to do???

Have an update. I have determined that:

var selection = window.getSelection().toString();

when compiled and executed under ExeOutput does collect the entire clipboard. But the call to the procedure was only accepting x amount of chars. Why? It stopped when it encountered a / (forward slash) in the clipboard. I can probably work around that.

exeoutput.RunHEScriptCom(“UserMain.OpenEmailClient|” + selection + “”);

procedure OpenEmailClient(B: String);
Var
S: String;
M: String;
begin
MessageBox(“running OpenEmailClient”,“OpenEmailClient”,MB_OK);
MessageBox(B,“B variable”,MB_OK);
S := “mailto:?body=”;
M := S+B;
MessageBox(M,“M variable”,MB_OK);
OpenFile(M, “”, SW_SHOWNORMAL);
end

But here’s is what is happening now. Both the B and M MessageBox display the clipboard with the CRLF (format looks good). But when the OpenFile pastes the body to the email client, all the CRLF’s have been removed. Sigh.

What about replacing CRLF characters with some other ones? So that when you get the email, you replace the characters by CRLF back yourself?

Not sure how I would do that. In my example, var M is fine (or looks fine in the messagebox) but after the OpenFile the text is placed in the body without CRLF’s.

May I clarify a couple of things before proceeding…

  1. Is it true I will not be able to do a “window.location.href” from a compiled ExeOuptut? Like I posted earlier, it works on localhost but not after the program is compiled.

  2. I have been unable to get past the / issue when calling the UserMain procedure. I have tried numerous JavaScript replaces but none have worked when calling the procedure. I can get the replaces to work on localhost. I tried the following with no luck:

var selection2 = selection.replace("/", “//”); // this failed

var selection2 = selection.replace("/", “\/”); // this failed

var selection2 = selection.replace("///", “\/”); // this failed

Do I need to change how the string is defined in the procedure?

exeoutput.RunHEScriptCom(“UserMain.OpenEmailClient|” + selection2 + “”);

procedure OpenEmailClient(B: String);
Var
S: String;
M: String;
begin
MessageBox(“running OpenEmailClient”,“OpenEmailClient”,MB_OK);
MessageBox(B,“B variable”,MB_OK);
S := “mailto:?body=”;
M := S+B;
MessageBox(M,“M variable”,MB_OK);
OpenFile(M, “”, SW_SHOWNORMAL);
end

This should help you:

function ReplaceString(const Original,OldPattern, NewPattern: string): String;

http://www.exeoutput.com/help/scriptreference

Thank you. I will try that.

Please confirm 1) Is it true I will not be able to do a “window.location.href” from a compiled ExeOutput? Like I posted earlier, it works on localhost but not after the program is compiled.

There is no known reason why window.location.href would not work.

Well, maybe there is now? Hopefully someone else can try and let the community know. It will not work for me under ExeOutput. Just a simple test of window.location.href = ‘mailto:[email protected]’; or any address.

Thanks

After further review, not sure what the function ReplaceString will do if the variable already gets truncated, when it hits a /, after it’s sent to the procedure.

If I can get window.location.href to work in the JavaScript code, within the PHP program, that would solve and simplify all of this.Can someone please test this. Wouldn’t take more than a couple of minutes to see if the call works after a compile.

window.location.href = ‘http://www.google.com’; // works
window.location.href = ‘mailto:[email protected]’; // fails

Is there something going on that prevents mailto from working under ExeOutput?

CEF is probably not configured to do something with the mailto: protocol. We’ll check whether it can be implemented.

Found a solution for the mailto: issue.

Saw this: Mailto: doesn't work in Chromium (SOLVED)

and implemented this in my JavaScript:

window.location.href = ‘heexternal://mailto:[email protected]’;

and it worked!

1 Like