vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Can Javascript be run from the plugin system? (https://vborg.vbsupport.ru/showthread.php?t=133371)

JPnyc 12-06-2006 07:49 PM

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.

Kirk Y 12-07-2006 12:52 AM

Not to my knowledge, no. AFAIK, Plugins can only be used to execute PHP Code.

Guest190829 12-07-2006 01:02 AM

Yes, you can add html and javascript to the headinclude variable before the template is called.

JPnyc 12-07-2006 03:41 AM

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.

Paul M 12-07-2006 04:18 AM

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).

JPnyc 12-07-2006 01:14 PM

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.

JPnyc 11-29-2007 11:08 AM

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

Marco van Herwaarden 11-29-2007 11:33 AM

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.

JPnyc 11-29-2007 12:11 PM

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

RedTyger 11-29-2007 12:33 PM

1 Attachment(s)
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.


All times are GMT. The time now is 02:31 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01135 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete