The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Can Javascript be run from the plugin system?
I did search on this but got no hits. Can javascript be run from the plugin system, or just php? I have a script that I want run onload of the showthread template. The onload event handler is contained within the script. I tried it on various showthread hooks, but no dice. I know the script works, since I've placed it into the showthread template to test, and it works.
|
#2
|
||||
|
||||
Not to my knowledge, no. AFAIK, Plugins can only be used to execute PHP Code.
|
#3
|
|||
|
|||
Yes, you can add html and javascript to the headinclude variable before the template is called.
|
#4
|
|||
|
|||
Ah so the <script> tags should be included? What if I want the script to run from the body instead of the head of the doc? It's only needed on the showthread template, so to put it into the headinclude seems overkill. Also, for some reason, when included in the head, the script doesn't work, when moved to the body, it does. Obviously some conflict with some other script in the head.
|
#5
|
||||
|
||||
You can just code the plugin to only add it to headinclude if showthread is being called (allthough that won't fix your second problem of it not working).
|
#6
|
|||
|
|||
Right, for some reason it only functions when outside the head of the doc. I might have to hardcode it into the template as I've been doing. The plugin system is a tremendous step forward for companies like ours who run 30 forums in vb format. When we go to upgrade, being able to just upload all the customizations rather than adding them by hand, is just a godsend.
|
#7
|
|||
|
|||
Sorry for reviving an old thread, but it was mine to begin with so I hope no one minds, and the subject is still the same. I need to execute some Javascript from the plugin system and not sure how to go about it. Can I use PHP to spit out or execute the JS? If so, would echo or eval be used? Can I just put a javascript directly into the plugin system and have it execute on a hook? Thanks
|
#8
|
|||
|
|||
Plugins are executing PHP and are executed server-side.
JavaScript is embeded in them HTML page, and is executed on the client-side. You can put JS in your templates, use echo (echo is not advised in plugins) or assign your JS code to a variable in a plugin and include that variable in a template. You can however never execute JS in a plugin as JS does not execute on the server-side. |
#9
|
|||
|
|||
okay thanks, but I could use PHP in a plug-in to write a JavaScript function to the page, on a given hook, could I not? I mean passing it through PHP as a string literal.
We run 30 forums, and I'm looking for a way to have these alterations be part of the plug-in system, so that I can just upload an XML file rather than making manual changes to templates on 30 forums. Thanks |
#10
|
||||
|
||||
The attached product should do what you want. When installed, the source code of showthread looks like this, changes highlighted in bold:
Code:
<script type="text/javascript" src="clientscript/vbulletin_global.js?v=367"></script> <script type="text/javascript" src="clientscript/vbulletin_menu.js?v=367"></script> <!-- END TEMPLATE: headinclude --><script type="text/javascript" src="clientscript/yourscript.js"></script> and Code:
<body onload="do_js();"> You'll have to edit the product to change what javascript is added, of course. Make sure the semicolon at the end of the onload bit is left, sometimes other onload javascript is included too, apparently. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|