最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught SyntaxError: missing ) after argument list

programmeradmin0浏览0评论
This question already has answers here: WordPress v5.0.3 Gutenberg & JS error "Uncaught SyntaxError: missing ) after argument list" (3 answers) Closed 5 years ago.

I'm getting this error when loading my page. I have 5.0.3 of WordPress.

Uncaught SyntaxError: missing ) after argument list
:formatted:1845

The link redirect to this code:

<script type='text/javascript'>( 'fetch' in window ) || document.write( '<script src=".min.js' defer onload='"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=".min.js' defer onload='"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=".min.js' defer onload='"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=".min.js' defer onload='"></scr' + 'ipt>' );

This question already has answers here: WordPress v5.0.3 Gutenberg & JS error "Uncaught SyntaxError: missing ) after argument list" (3 answers) Closed 5 years ago.

I'm getting this error when loading my page. I have 5.0.3 of WordPress.

Uncaught SyntaxError: missing ) after argument list
:formatted:1845

The link redirect to this code:

<script type='text/javascript'>( 'fetch' in window ) || document.write( '<script src="https://learn.blueworkforce/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js' defer onload='"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src="https://learn.blueworkforce/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js' defer onload='"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src="https://learn.blueworkforce/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js' defer onload='"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src="https://learn.blueworkforce/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js' defer onload='"></scr' + 'ipt>' );

Share Improve this question edited Feb 18, 2019 at 15:16 Max Yudin 6,3882 gold badges26 silver badges36 bronze badges asked Feb 18, 2019 at 15:10 jn bluejn blue 11 bronze badge 2
  • This is core.trac.wordpress/ticket/46110 that file is only loaded if SCRIPT_DEBUG is set – Tom J Nowell Commented Feb 18, 2019 at 15:31
  • The code posted fails before the wp-polyfill-formdata is run. For whatever reason the script output is broken. (possibly filtered by something) It will fail on all browsers. – Tim Commented Mar 29, 2019 at 15:28
Add a comment  | 

2 Answers 2

Reset to default 0

You have the same error repeated on each script. Look at the attribute delimiters. They start using double quotes, then switch:

<script src="https://...js' defer onload='">
                          ^              ^

Should be:

<script src="https://...js" defer onload="">

The first single quote I've marked, ends the enclosing string. That's not invalid, but not what is intended. Everything after that point is just waiting for a syntax error to occur.

I don't know how these mistakes ended up in your code, but I note that they are not as the WordPress core outputs the scripts normally.

My guess is that the following string has been spliced into the script output expecting that single quotes would be used.

' defer onload='

Possibly some plugin is doing this to all scripts with some filter, possibly Mos Speed up which seems to do this.

The problem is due to WordPress Gutenberg's some js which doesn't support defer. I had the same problem, I have added a WordPress hook to defer js. I have added a condition now that the hook will not call on admin pages and it fixed my issue.

OLD code:

add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

New code:

if ( !is_admin() ) {
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}

after this code, it is not adding defer to admin side scripts and it saved me.

发布评论

评论列表(0)

  1. 暂无评论