Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Can I use MetaMod to call a...
Can I use MetaMod to call a Javascript function?
Can I use MetaMod to call a Javascript function?
First of all - many, many thanks for what I consider to be the most useful module I use. And the Pro plugin just makes everything perfect!
I have a need to call a Javascript OnLoad function when certain pages on my site load, but only the first time the page loads for each visit. Can I use MetaMod somehow to issue a simple OnLoad call?
Thanks!
Rick
Re: Can I use MetaMod to call a Javascript function?
Hi Momentis,
yes, you could use MetaMod for this, though I would think that this sort of functionality would be better to put into the template. Similar PHP code would be used in each case.
If you do want to use MetaMod (hey why not...) then you can do it like this:
Code:
if ( conditions here... ) {
?><script type="text/javascript">
... script here...
</script>
<?php
}
Note that even with MetaMod Pro, this will force a module to be published in whatever module position it's in. So make sure you turn off the Metamod title, and you might need to do something with the module class suffix too, if you get borders or spacing issues. I'd publish this to a module position at the very bottom of the page where there are less likely to be spacing issues.
Hope this helps,
Stephen
Re: Can I use MetaMod to call a Javascript function?
metamodguy wrote:
Note that even with MetaMod Pro, this will force a module to be published in whatever module position it's in. So make sure you turn off the Metamod title, and you might need to do something with the module class suffix too, if you get borders or spacing issues. I'd publish this to a module position at the very bottom of the page where there are less likely to be spacing issues.
That makes sense. I am already using MetaMod on the page for another module, so could I bury my code to execute right in there with it? I'd assume I could. Anyway, thanks for the help!
Re: Can I use MetaMod to call a Javascript function?
Yes, but just remember that the HTML/JS output from the MetaMod itself (as opposed to the modules that it includes) are going to get put into a brand new module if you're using MetaMod Pro. If there's output, it will become a new module. If there's none, no module will appear at all (not even an empty one). So the extra JS will become a module in its own right. This may or may not matter -- depends on your template.
Cheers,
Stephen
Re: Can I use MetaMod to call a Javascript function?
I'm wanting to use the ?> ...code ...<?php trick to insert some javascript but having no luck. Indeed even something like the following is failing -
Code:
?>
<b>Some HTML here</b>
<?php
With this in the module, nothing appears. If I add some metamod code anywhere else (like say return 45; at the top), then it's not processed either. Turning on "debug" the module appears with debug info, but still doesn't show anything from the code.
I'm using metamod 2.2c and metamod pro plugin 2.1
Is this a bug or am I missing something obvious?
Re: Can I use MetaMod to call a Javascript function?
There's a possibility that you need to have at least 1 character at the start and end of the PHP script. Try this:
Code:
//
?>
<b>Some HTML here</b>
<?php
//
"//" designates a comment, so there's no problem putting that in your PHP.
Hope it works,
Stephen
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Can I use MetaMod to call a...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7629
- Newest User:
- claudiabush9
- Members Online:
- 1
- Guests Online:
- 162
- Online:
- claudiabush9
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked