Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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

momentis
Web Developer
Beginner Modder
ranks
useravatar
Offline
12 Posts
User info in posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

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!

momentis
Web Developer
Beginner Modder
ranks
useravatar
Offline
12 Posts
User info in posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

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?

david steadson
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Can I use MetaMod to call a Javascript function?

thanks Stephen, that solved it! I'd tried with extra text at the beginning, but not the end. With both it works a charm!

Constantly amazed at the flexibility and power metamod gives me with Joomla smile

david steadson
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1689
Total Polls:
6
Total Posts:
5941
Posts this week:
1
User Info:
 
Total Users:
5339
Newest User:
trei50809
Members Online:
0
Guests Online:
138

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked