-
Notifications
You must be signed in to change notification settings - Fork 4.7k
How can I add pure js code to index.html
#790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Working with the config.js-approach: module.exports = {
head: [ ['script', {}, `
var _hmt = _hmt || [];
(function() {
var hm = document.createElement(“script”);
hm.src = “//hm.baidu.com/hm.js?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
var s = document.getElementsByTagName(“script”)[0];
s.parentNode.insertBefore(hm, s);
})();
`]]
} This works, because of the head-option's signature: ['tagname', attributesObject, contentString] |
Thanks, it works. |
@ulivz Can we use similar technique to add it to the |
would love to know how it works for adding script to body. |
@ulivz How to add pure javascript code to the |
@anisabboud See earlier comment, you need to do it in config.js |
@rajaraodv config.js is a workaround that adds the script to the I was wondering if there's a new way to add it to the |
@ulivz any updates here, please? |
On possible approach to add script to body is using the same technique as @Tom-Julux showed:
Note: since this code is running from It's also possible to delete this script from the page if needed using the assigned id |
Bug report
Such as Baidu Statistics code,we usually add a piece of pure js code to index.html :
How can I add those code to Vuepress ?
Version
Vuepress 0.14.2
Steps to reproduce
I try to add those code to
config.js
:But I don't know how to do it.
Then I use a third part library
vue-ba
install
then I modified
enhanceApp.js
:when compiling,some error were outputed in console:
What is expected?
Expose
window
in enhanceApp.js, or a mechanism for adding pure js code.What is actually happening?
Other relevant information
The text was updated successfully, but these errors were encountered: