MyBB Community Forums

Full Version: Where to put javascript?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi guys,

Please excuse me, I'm pretty new at this whole thing. I want to make a new page and I followed a couple of tutorials which had me creating a new template and calling it from newpage.php

I have some javascript I would like to play with as well. It allows an image to be dragged accross a page and placed anywhere.

I've placed the javascript in newpage.php as $javascript = ' a heap of js ';

Then in my newpage template I called it with {$javascript} between the <head> tags.

It doesn't seem to work...

I have tried placing {$javascript} in different places to no avail. I think I am missing something here?
Just enter your javascript in the new template which you created after <head> & before closing of </head> tag and it would work fine.

You can also enter it in templates > your theme templates > ungrouped templates > headerinclude , but it would call your javascript on all pages then.
thanks crazy4cs. I was kind oh hoping to keep it out of the template and keep the template as a default for all new pages I wanted to add and then custom the php page but I guess its not the correct way to do it. I am guessing the correct way is to use a specific template for each page.

I'll try it in the template and see how it goes, cheers

yeah it didn't work. The javascript works fine if I stick it inside a test.html or test.php so I dont think there is anything wrong with the script.
Then paste your code (only js code) in headerinclude template. What is the issue you're facing exactly?
It just fails to work, trying to understand how it all fits together but its a learning curve for me.

I am not sure what I am trying to do is even doable. I want the normal headers, and footers, as well as the theme (default in this case). I then want to display a couple of images that you can drag and drop around.
I can see the images, but they wont drag and drop.
When I make a new page I create a new template in my global templates. What you could do is then insert the standard script tags into your template just before the head

Example:
<html>
<head>
<title>{$mybb->settings['bbname']}</title>
{$headerinclude}
< PUT YOUR LINK TO THE EXTERNAL JS HERE>
</head>
<body>
{$header}
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
	<tr>
		<td class="thead" colspan="2">
			<div>
				<strong>Title</strong>
			</div>
		</td>
	</tr>
	<tr>
		<td>
CONTENT
		</td>
	</tr>
</table>
{$footer}
</body>
</html>
Also make sure you enter your javascript content in between script tags like this in template;

<script type="text/javascript">
//Your js codes goes here
</script>

Or paste your whole template code so we can see and fix for you.
iam putting this code in headerinclude bt it dnt show anything, i putted it directly into header templete but no effect..code is

<script type="text/javascript"><!--
dp_ad_color_title = "#f20e0e";
dp_ad_color_desc = "#0f0e0e";
dp_ad_color_background = "#56ff56";
dp_ad_fallback = "youradhere";
dp_ad_notice = 7;
//--></script><script type="text/javascript" src="http://s.dpstatic.com/s/ad.js"></script>
(2012-08-25, 05:29 PM)danyalsad Wrote: [ -> ]iam putting this code in headerinclude bt it dnt show anything, i putted it directly into header templete but no effect..code is

<script type="text/javascript"><!--
dp_ad_color_title = "#f20e0e";
dp_ad_color_desc = "#0f0e0e";
dp_ad_color_background = "#56ff56";
dp_ad_fallback = "youradhere";
dp_ad_notice = 7;
//--></script><script type="text/javascript" src="http://s.dpstatic.com/s/ad.js"></script>

Um... where i come from, this means a comment...

<!-- -->

Try

<script type="text/javascript" src="http://s.dpstatic.com/s/ad.js"></script>
<script type="text/javascript">
dp_ad_color_title = "#f20e0e";
dp_ad_color_desc = "#0f0e0e";
dp_ad_color_background = "#56ff56";
dp_ad_fallback = "youradhere";
dp_ad_notice = 7;</script>
dont you think u missed </script> at the end ?
Pages: 1 2