• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Don't Laugh at Me: How to Add JS to Widget to Display Text

Scheduled Pinned Locked Moved Technical Support
4 Posts 2 Posters 1.8k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • rodR Offline
    rodR Offline
    rod
    wrote on last edited by
    #1

    Please keep all snickering to a quiet din!

    How would I go about creating a script to display text in a NodeBB widget based on the value of a variable? For example when I try the following I get an error that document.write is not a function.

    <script type="text/javascript">
    {
        if(app.user.username === me) {
    		document.write('Display This Information');
        }
    }
    </script>
    

    Thank you.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by baris
    #2

    You want something like this

    <script type="text/javascript">
        if(app.user.username === 'me') {
             $('#someElement').html('some content')
        }
    </script>
    
    rodR 1 Reply Last reply
    1
  • rodR Offline
    rodR Offline
    rod
    replied to <baris> on last edited by
    #3

    @baris Thank you. It is working great.

    1 Reply Last reply
    0
  • rodR Offline
    rodR Offline
    rod
    wrote on last edited by
    #4

    I have to say that programmatically being able to show and hide content in a widget is fabulous. I now have a Global > Global Header widget that displays an image and text only when it is the "home" page.

    This is how I implemented one widget:

    <widgetGH1></widgetGH1>
    <script type="text/javascript">
        if(location.href === 'https://example.com/') {
             $('widgetGH1').html('<img src="//example.com/uploads/image.png">  Site Welcome Text');
        }
    </script>
    
    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development