Hello every body,
I'm using addToJavaScriptWindowObject and evaluateJavaScript to inject and evaluate the script output2 at a web page,
the injected script "output2" used to extract the names of javascript function of a web page,
Then I get the names of these functions and I execute them with the script "ss",
void Webkit::applyscript2()
{
QFile file ("exemple/onclick.js");
{ qDebug()<< "le fichier n'existe pas " ; return;}
file.close();
QWebFrame* f = v.page()->mainFrame();
if (!dataScript) {
dataScript = new ApplyScript();
f->addToJavaScriptWindowObject("linkCssOutput", dataScript);
}
QVariant vrr
= f
->evaluateJavaScript
(output2
);
fct_script =dataScript->getLink();
int j;
for (j=0;j<fct_script.size();j++)
{QString contenu_fct
=fct_script
[j
];
QString ss
=QString("var f='window.addEventListener(\"load\",'+%1+', false);';" "var ff='window.attachEvent(\"onload\",%1);';"
" if (window.addEventListener) {alert (\"dans if\" ); "
"eval(f);"
"} else if (document.addEventListener) { "
"eval(f);"
"} else if (window.attachEvent) {"
"eval(ff);"
"}").arg(contenu_fct);
QVariant vrr
= f
->evaluateJavaScript
(ss
);
}
}
/////////// setLink et getLink //////////////
void ApplyScript
::setLink(const QString & data
) {
qDebug()<< "data "<< data;
m_data.push_back(data) ;
}
QVector <QString>
& ApplyScript
::getLink( ) {
return m_data;
}
void Webkit::applyscript2()
{
QFile file ("exemple/onclick.js");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ qDebug()<< "le fichier n'existe pas " ; return;}
QTextStream out(&file);
QString output2 = out.readAll();
file.close();
QWebFrame* f = v.page()->mainFrame();
if (!dataScript) {
dataScript = new ApplyScript();
f->addToJavaScriptWindowObject("linkCssOutput", dataScript);
}
QVariant vrr = f->evaluateJavaScript(output2);
fct_script =dataScript->getLink();
int j;
for (j=0;j<fct_script.size();j++)
{QString contenu_fct =fct_script[j];
QString ss=QString("var f='window.addEventListener(\"load\",'+%1+', false);';"
"var ff='window.attachEvent(\"onload\",%1);';"
" if (window.addEventListener) {alert (\"dans if\" ); "
"eval(f);"
"} else if (document.addEventListener) { "
"eval(f);"
"} else if (window.attachEvent) {"
"eval(ff);"
"}").arg(contenu_fct);
QVariant vrr = f->evaluateJavaScript(ss);
}
}
/////////// setLink et getLink //////////////
void ApplyScript::setLink(const QString & data)
{
qDebug()<< "data "<< data;
m_data.push_back(data) ;
}
QVector <QString> & ApplyScript::getLink( )
{
return m_data;
}
To copy to clipboard, switch view to plain text mode
but I can't get their results of execution, can you help me?
For example I have the javascript fonction:
<script type="text/javascript">
function google() {
var a ="http://";
var b="www.google.com" ;
window.location.href = a+b ;
}
</script>
<script type="text/javascript">
function google() {
var a ="http://";
var b="www.google.com" ;
window.location.href = a+b ;
}
</script>
To copy to clipboard, switch view to plain text mode
I get the function name (google()) then I executed it ,but how can I get result of his execution "value of QVariant vrr = f->evaluateJavaScript(ss);".
in this case is the url "http://www.google.com"
I have long search a way and I have not find
can you help me
thank you for any assistance,
Bookmarks