Add RunScriptAsync() to webview sample
This commit is contained in:
@@ -122,6 +122,7 @@ public:
|
||||
void OnTitleChanged(wxWebViewEvent& evt);
|
||||
void OnFullScreenChanged(wxWebViewEvent& evt);
|
||||
void OnScriptMessage(wxWebViewEvent& evt);
|
||||
void OnScriptResult(wxWebViewEvent& evt);
|
||||
void OnSetPage(wxCommandEvent& evt);
|
||||
void OnViewSourceRequest(wxCommandEvent& evt);
|
||||
void OnViewTextRequest(wxCommandEvent& evt);
|
||||
@@ -159,6 +160,7 @@ public:
|
||||
void OnRunScriptArrayWithEmulationLevel(wxCommandEvent& evt);
|
||||
#endif
|
||||
void OnRunScriptMessage(wxCommandEvent& evt);
|
||||
void OnRunScriptAsync(wxCommandEvent& evt);
|
||||
void OnRunScriptCustom(wxCommandEvent& evt);
|
||||
void OnAddUserScript(wxCommandEvent& evt);
|
||||
void OnSetCustomUserAgent(wxCommandEvent& evt);
|
||||
@@ -233,6 +235,7 @@ private:
|
||||
#endif
|
||||
wxMenuItem* m_script_message;
|
||||
wxMenuItem* m_script_custom;
|
||||
wxMenuItem* m_script_async;
|
||||
wxMenuItem* m_selection_clear;
|
||||
wxMenuItem* m_selection_delete;
|
||||
wxMenuItem* m_find;
|
||||
@@ -492,6 +495,7 @@ WebFrame::WebFrame(const wxString& url) :
|
||||
m_script_array_el = script_menu->Append(wxID_ANY, "Return array changing emulation level");
|
||||
}
|
||||
#endif
|
||||
m_script_async = script_menu->Append(wxID_ANY, "Return String async");
|
||||
m_script_message = script_menu->Append(wxID_ANY, "Send script message");
|
||||
m_script_custom = script_menu->Append(wxID_ANY, "Custom script");
|
||||
m_tools_menu->AppendSubMenu(script_menu, _("Run Script"));
|
||||
@@ -551,6 +555,7 @@ WebFrame::WebFrame(const wxString& url) :
|
||||
Bind(wxEVT_WEBVIEW_TITLE_CHANGED, &WebFrame::OnTitleChanged, this, m_browser->GetId());
|
||||
Bind(wxEVT_WEBVIEW_FULLSCREEN_CHANGED, &WebFrame::OnFullScreenChanged, this, m_browser->GetId());
|
||||
Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &WebFrame::OnScriptMessage, this, m_browser->GetId());
|
||||
Bind(wxEVT_WEBVIEW_SCRIPT_RESULT, &WebFrame::OnScriptResult, this, m_browser->GetId());
|
||||
|
||||
// Connect the menu events
|
||||
Bind(wxEVT_MENU, &WebFrame::OnSetPage, this, setPage->GetId());
|
||||
@@ -596,6 +601,7 @@ WebFrame::WebFrame(const wxString& url) :
|
||||
#endif
|
||||
Bind(wxEVT_MENU, &WebFrame::OnRunScriptMessage, this, m_script_message->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnRunScriptCustom, this, m_script_custom->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnRunScriptAsync, this, m_script_async->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnAddUserScript, this, addUserScript->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnSetCustomUserAgent, this, setCustomUserAgent->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnClearSelection, this, m_selection_clear->GetId());
|
||||
@@ -924,6 +930,11 @@ void WebFrame::OnScriptMessage(wxWebViewEvent& evt)
|
||||
wxLogMessage("Script message received; value = %s, handler = %s", evt.GetString(), evt.GetMessageHandler());
|
||||
}
|
||||
|
||||
void WebFrame::OnScriptResult(wxWebViewEvent& evt)
|
||||
{
|
||||
wxLogMessage("Async script result received; value = %s", evt.GetString());
|
||||
}
|
||||
|
||||
void WebFrame::OnSetPage(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
m_browser->SetPage
|
||||
@@ -1199,6 +1210,11 @@ void WebFrame::OnRunScriptMessage(wxCommandEvent& WXUNUSED(evt))
|
||||
RunScript("window.wx.postMessage('This is a web message');");
|
||||
}
|
||||
|
||||
void WebFrame::OnRunScriptAsync(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
m_browser->RunScriptAsync("function f(a){return a;}f('Hello World!');");
|
||||
}
|
||||
|
||||
void WebFrame::OnRunScriptCustom(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
wxTextEntryDialog dialog
|
||||
|
Reference in New Issue
Block a user