Closed ngshiheng closed 3 years ago
If you want to include your javascript file, you can use the RequireJs built-in pywebio.
If you only want to execute some js code, just use pywebio.session.run_js()
function.
What I wanted to do is to copy and paste the AdSense code in between the <head></head>
tags of my site.
This is the example code snippet that I want to include:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxx"
crossorigin="anonymous"></script>
Does this work?
run_js("""
$('head').append('<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxx"
crossorigin="anonymous"></script>')
"""
Thanks for the quick reply man. Just tried it out, it doesn't append the script tag inside
, not even anywhere elseSorry, a redundant linebreak was incorrectly added to the code, the correct code is:
run_js("""
$('head').append('<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxx" crossorigin="anonymous"></script>')
"""
The above code does insert the script tag to head, you need use chrome's inspect panel to check the result rather than "View page source":
Oh yea, I see it now on the inspect panel. I kept looking from the page source. Thank you so much for your help. Let's see if Adsense works 🤞 Closing the issue now. Thanks.
If you want to include your javascript file, you can use the RequireJs built-in pywebio.
do you have some examples or documentation about this? I'm not very familiar with frontend and JS and need some clue. To be specific, I'm looking for a way to have templates or themes for my PuWebIO website. (does not matter Bootstrap or Boilerplate JS) Thanks
Hi, may I know is there a way I can add some more
<script>
tags inside the<head>
section of the default HTML>?