ExecuteJavaScript backslash?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

ExecuteJavaScript backslash?

Postby js532 » Wed May 25, 2016 3:29 pm

Using a backslash in the string for the script won't work as expected.
Example: file path - Won't display any slashes.

If I use new line (\n) it won't even execute the script.
Did I miss something? I have the next to the last cef version and I call executejavascript always from the mainframe in the right thread.
js532
Newbie
 
Posts: 7
Joined: Mon Apr 04, 2016 6:03 pm

Re: ExecuteJavaScript backslash?

Postby magreenblatt » Wed May 25, 2016 9:17 pm

Example?
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript backslash?

Postby js532 » Thu May 26, 2016 8:53 am

std::string test = "C:\\test";

frame = GetBrowser()->GetMainFrame();
frame->ExecuteJavaScript("alert('" + test + "');", frame->GetURL(), 0);

> displays: C: est

or

std::string test = "test\n";

frame = GetBrowser()->GetMainFrame();
frame->ExecuteJavaScript("alert('" + test + "');", frame->GetURL(), 0);

> no execution at all.
js532
Newbie
 
Posts: 7
Joined: Mon Apr 04, 2016 6:03 pm

Re: ExecuteJavaScript backslash?

Postby Czarek » Thu May 26, 2016 10:51 am

Open DevTools > console in Chrome and execute your code:

Code: Select all
alert("C:\test")


Code: Select all
alert("test
")
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: ExecuteJavaScript backslash?

Postby js532 » Thu May 26, 2016 11:18 am

For path disclosures I need to double the backshlashes and transform the string before I call execute java script..
C:\\\\test as example gives the result I want: C:\\test (Chrome Console)
Using CEF JavaExecuteScript I need to quadruple the shlashes.

New line (\n) only works in chrome console.
js532
Newbie
 
Posts: 7
Joined: Mon Apr 04, 2016 6:03 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 57 guests