MyBB Community Forums

Full Version: How do I enable "script" tags in posts?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I was experimenting and tried exactly what you said right before you posted this Smile

Unfortunately, it converts it back to the raw script code and displays it as text, exactly as if the script code itself had been entered. It's as though the forum knows to check for it and disable it even after MyCode has been in play.
Hmm really? It works okay on my test board... you did put the script in the 'Replacement' field, yeah?
Correct.  It successfully replaces the mycode with the script, but the script still just shows up as plain text in both previews and in posts when I test it out.

What was interesting was that when I used the little test sandbox at the bottom of the MyCode adder, the text DID NOT show up plain at all in the "actual result" section.  This made me think it was a success, but then when I try it in an actual post it just shows up as plain text again.
Ah, weird, seems if I have HTML turned off it puts the script in properly, but then if HTML is allowed in posts, it then forcefully strips the <script> tags out... hmm. I'll try and have a think of a way around it...
Ah, makes sense. I definitely appreciate the willingness to help out, Matt. I have subscribed to this thread so if you do happen to think of a workaround, I will still see this. If there's no way to do it, I still appreciate the attempts. Smile

I found a temporary solution by adding this code into the footer of my forum:

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

And so now, when the user adds the HTML section (without the script widget at the bottom) it seems to convert it into the format it's supposed to be. Are there any risks I need to be aware of with this method though? Leaving that code permanently in my footer template?
Ha, of course, yes that would work. That's perfectly safe to put in your template; javascript itself isn't malicious but it can be used maliciously, which is why allowing users to use it is extremely dangerous, but no, this would be fine. As far as I'm aware, these Twitter widgets will work as long as that script is included anywhere on the page (they just put it after the HTML so it's always included at least once), but as long as it's on the page somewhere it should work. That didn't even occur to me! D'oh Blush
With the latest MYBB version 1.8......how do we easily allow users to post the twitter post, so it is embedded in the post at Twitter intended?

Thanks!
Pages: 1 2