Problem with making an HTML+Javascript button
-
Hello!
I’d like to preface this by saying I know next to nothing about coding ; everything I have here was obtained by following tutorials so please be gentle.
I’m trying to create a button on my website which generate a random title from a set list. The html file works just fine in my browser and even in the preview section of my wordpress page. But when I try to publish the page, I get a block of text in place of the button. Here are some screenshots
And here is my code:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <div id="articleDisplay"> </div> <button onclick="genArticle()">Nouvel Article</button> http://javascript.js <script type="text/javascript"> var articles = [ "Encyclopédie", "Spéculation", "Vérité", "Infox", "Information", "Théorie", "Théorie du complot", "Poste-vérité", "Conspirationnisme", "Conspiration", "Interprétation", "Hypothèse", "Parti pris", "Média", "Internet", "Connaissance" ] function genArticle() { var randNum = Math.floor(Math.random() * 16); document.getElementById('articleDisplay').innerHTML = articles[randNum]; } </script> </body> </html>What can I do? It’s quite likely my code is wrong, but I’m surprised/confused as to how it could be working in the preview and not when published… Could it be a problem with the theme?
The blog I need help with is: (visible only to logged in users)
-
Hi there, Because WPcom is a shared environment, javascript code is not allowed unless your site is on the WPcom Business or eCommerce plans, whose sites are on different servers and you can run such scripts.
You can read more about this here: https://en.support.wordpress.com/code/
So in short, it would not be possible to create a random title generator in this way on the free site plan.
- The topic ‘Problem with making an HTML+Javascript button’ is closed to new replies.