News:

Wondering if this will always be free?  See why free is better.

Main Menu

Insert JavaScript into index.template.php

Started by me1982, March 06, 2011, 10:20:56 AM

Previous topic - Next topic

me1982

Hi folks,

I hope somebody can help me. I added some javascriptcode to my index.template.php, to open a new window on a link click. I did it like this:
Quote

// Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'];

   echo '
   <script type="text/javascript">function open_win()
      {
         window.open [nofollow](
            "somesiteof.php","sitename","width=400,heigt=400"
         );
      }
   </script>
</head>
<body>';
}

It only opens the window, but doesn't compute any of the specs / attributes. If I change it to this:
Quote

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'];

   echo '
   <script type="text/javascript">function open_win()
      {
         window.open [nofollow](
            'somesiteof.php','sitename','width=400,heigt=400'
         );
      }
   </script>
</head>
<body>';
}
,

like w3schools is advising to do it, the webpage doesn't show any of the theme anymore. Plus, most of the content is just gone.

So, what would be the right way to do it? It is supposes to result in a link that can open a window, which is fix in its size.

The linkcode looks like this:
Quote
<a href="javascript:open_win();">link</a>


I use smf 2.0 rc5.

Greetz!

Matthew K.

For the second method, single quotes should be escaped. Find: ' Replace: \'

ascaland

Dont forget to fix that spelling mistake: heigt.

me1982

Found the spelling misstake already. thx for the hint.

Works, thx a lot. Is this php related?

Arantor

The whole issue of the ' is SMF/PHP related, because the code is being sent from PHP, and in PHP both ' and " have significance - you can't use a ' inside a '...' block without putting \ in front of it (much as in Javascript)

The benefit of using ' in Javascript is fairly minimal compared to " anyway though. It's more significant in PHP.

me1982

Thx.

I worked the whole day on the page which should go into the new window, to realize, that it doesnt work with my routine. so thanks a lot guys. works pretty fine and i am satisfied with the result.

Advertisement: