fix: js undefined error (#1298)

* fix: js undefined error

* [autofix.ci] apply automated fixes

---------

Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-11-23 22:00:19 +08:00 committed by GitHub
parent 8ea4ef84d9
commit fb85f68b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -674,8 +674,8 @@ void ArticleRequest::bodyFinished()
fmt::format_to( std::back_inserter( head ), fmt::format_to( std::back_inserter( head ),
FMT_COMPILE( FMT_COMPILE(
R"( <div class="gdarticle {0} {1}" id="{2}" R"( <div class="gdarticle {0} {1}" id="{2}"
onClick="gdMakeArticleActive( '{3}', false );" onClick="if(typeof gdMakeArticleActive !='undefined') gdMakeArticleActive( '{3}', false );"
onContextMenu="gdMakeArticleActive( '{3}', false );">)" ), onContextMenu="if(typeof gdMakeArticleActive !='undefined') gdMakeArticleActive( '{3}', false );">)" ),
closePrevSpan ? "" : " gdactivearticle", closePrevSpan ? "" : " gdactivearticle",
collapse ? " gdcollapsedarticle" : "", collapse ? " gdcollapsedarticle" : "",
gdFrom, gdFrom,

View file

@ -555,9 +555,10 @@ bool ArticleView::setCurrentArticle( QString const & id, bool moveToIt )
QString dictId = id.mid( 7 ); QString dictId = id.mid( 7 );
if ( dictId.isEmpty() ) if ( dictId.isEmpty() )
return false; return false;
QString script = QString( QString script =
QString(
"var elem=document.getElementById('%1'); " "var elem=document.getElementById('%1'); "
"if(elem!=undefined){elem.scrollIntoView(true);} gdMakeArticleActive('%2',true);" ) "if(elem!=undefined){elem.scrollIntoView(true);} if(typeof gdMakeArticleActive !='undefined') gdMakeArticleActive('%2',true);" )
.arg( id, dictId ); .arg( id, dictId );
onJsActiveArticleChanged( id ); onJsActiveArticleChanged( id );
webview->page()->runJavaScript( script ); webview->page()->runJavaScript( script );