News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

javascript button to open popup

Started by scrawl, July 29, 2005, 09:24:54 PM

Previous topic - Next topic

scrawl

i searched the forum and went through a million threads last night but couldn't find an answer so if this has been posted before sorry i couldn't find it.

problem:

i have my buttons along the top such as "home" "help" "store" etc but i want to add a new button but i need this button to open a javascript popup window. i've racked my brain over how to do this but i'm still learning i've tried different approaches but none worked. i'm guessing i need something similar to this

// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '
<a href="', $scripturl, '?action=admin">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];



but i can't figure out how i have a gif image open a javascript popup if that makes any sense like i want the button to run with my theme and don't want to use a standard form button. anyways any help would be greatly appreciated.

pce

scrawl

[Unknown]

Something like:

<a href="javascript:" onclick="window.open(\'', $scripturl, '?action=admin\'); return false;"><img ... /></a>

It's just basic HTML.

-[Unknown]

scrawl

cheers for the help [Unknown] but could there be an error in that code?

i've tried it as that but it says theres a error as well

but this is the code i'm trying to use

echo '
                                <a href="javascript:" onclick="window.open(\'', $scripturl, '?action=admin\'); return false;"'><($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/player.gif" alt="' . $txt[84] . '" border="0" />' : $txt[472]), $context['menu_separator'];/>\'</a>',

[Unknown]

Try:

echo '
<a href="javascript:" onclick="window.open(\'', $scripturl, '?action=admin\'); return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];


-[Unknown]

scrawl

#4
sweet that works but... haha i'ma dick where do i put the url for the html document i want it to popup. soz bro i really appreciate this.


i tried it like this

<a href="javascript:" onclick="window.open(\'http://www.google.com.au',

that's just a snippet of the full code but anyway it came up with the http at the end of the address i removed the http and it said it wasn't a valid address. cheers man


^^ i realise that's not right but where do i tell it the url for the html document. thanks bro

[Unknown]

You need the slash on both 's, so:

<a href="javascript:" onclick="window.open(\'http://www.google.com.au\'); return false;">

-[Unknown]

scrawl

#6
your a bloody legend, thanks heaps.

scrawl

f**k me i've tried everything every possible combination i can think of, i've scoured google and i've found the right code but nothing will work the closest i get is "error: setting a propert that has only a getter" and many other numerous errors. all i want to do is be able to specify the width and height of the window that opens. i'm thinking it should be simple some of the stuff i've tried.

<a href="javascript:" onclick="window.open(\'http://www.mylink.com/forum/music_player/music_player_003.html\'), \'width=200,height=150\');  return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/player.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];


^^didn't work^^

i also tried putting this in the heading and calling the function from <a href="javascript:popurl"

<script language="JavaScript" type="text/javascript"><!--
function openpopup(popurl){
var winpops=window.open(popurl,"","width=,height=")
}
// --></script>


but i don't think the area where i have my code can call the function from the head of the index.template.php document so yeh not one thing i've tried has worked. sorry to make a mound into a mountain i'm sure this is quite simple i'm just not built to code. anyways thanks for any help that's offered

kegobeer

I think your code is a little bit off.  First, the javascript function:

<script type="text/javascript">
<!--
var newwindow;
function poptastic(url)
{
newwindow=window.open(url,'name','height=400,width=200');
if (window.focus) {newwindow.focus()}
}
// -->
</script>


That can go anywhere really, but I like to put javascript in the <head>.

Next, the call:

<a href="javascript:poptastic('poppedexample.html');">Pop it</a>

This is from http://www.yourhtmlsource.com/javascript/popupwindows.html.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

scrawl

that looks cool cheers for the help but i need it to be called from a button on the menu (like where "home" "search" etc are) and the code for the menu buttons is located outside of the <body> so i don't think that'll work. but if it does how do i incorporate this

<a href="javascript:poptastic('poppedexample.html');">Pop it</a>

into this

echo '
<a href="javascript:" onclick="window.open(\'', $scripturl, '?action=admin\'); return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];



cheers for the help.

kegobeer

I don't understand - what do you mean "the code for the menu buttons is located oustide of the <body>"?  If the javascript function isn't in the head or the body, exactly where is it?

echo '
<a href="javascript:poptastic(\'' , $scripturl , '?action=admin\');">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

scrawl

#11
</table>';




// And then we're done!
echo '


</body>
</html>';
}

// Show a linktree.  This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree()
{
global $context, $settings, $options;

// Folder style or inline?  Inline has a smaller font.
echo '<span class="nav"', $settings['linktree_inline'] ? ' style="font-size: 10px;"' : '', '>';

// Each tree item has a URL and name.  Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
// Show the | | |-[] Folders.
if (!$settings['linktree_inline'])
{
if ($link_num > 0)
echo str_repeat('<img src="' . $settings['images_url'] . '/icons/linktree_main.gif" alt="| " border="0" />', $link_num - 1), '<img src="' . $settings['images_url'] . '/icons/linktree_side.gif" alt="|-" border="0" />';
echo '<img src="' . $settings['images_url'] . '/icons/folder_open.gif" alt="+" border="0" />&nbsp; ';
}

// Show something before the link?
if (isset($tree['extra_before']))
echo $tree['extra_before'];

// Show the link, including a URL if it should have one.
echo '<b>', $settings['linktree_link'] && isset($tree['url']) ? '<a href="' . $tree['url'] . '" class="nav">' . $tree['name'] . '</a>' : $tree['name'], '</b>';

// Show something after the link...?
if (isset($tree['extra_after']))
echo $tree['extra_after'];

// Don't show a separator for the last one.
if ($link_num != count($context['linktree']) - 1)
echo $settings['linktree_inline'] ? ' &nbsp;<img src="' . $settings['images_url'] . '/icons/folder_open.gif">&nbsp; ' : '<br />';
}

echo '</span>';
}

// Show the menu up top.  Something like [home] [help] [profile] [logout]...
function template_menu()
{
global $context, $settings, $options, $scripturl, $txt;

// Show the [home] and [help] buttons.
echo '
<a href="', $scripturl, '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/home.gif" alt="' . $txt[103] . '" border="0" />' : $txt[103]), '</a>', $context['menu_separator'], '
<a href="', $scripturl, '?action=help" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/help.gif" alt="' . $txt[119] . '" border="0" />' : $txt[119]), '</a>', $context['menu_separator'];

// How about the [search] button?
if ($context['allow_search'])
echo '
<a href="', $scripturl, '?action=search">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/search.gif" alt="' . $txt[182] . '" border="0" />' : $txt[182]), '</a>', $context['menu_separator'];

// Is the user allowed to administrate at all? ([admin])
if ($context['allow_admin'])
echo '
<a href="', $scripturl, '?action=admin">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];

// Edit Profile... [profile]
if ($context['allow_edit_profile'])
echo '
<a href="', $scripturl, '?action=profile">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/profile.gif" alt="' . $txt[79] . '" border="0" />' : $txt[467]), '</a>', $context['menu_separator'];
echo '
<a href="', $scripturl, '?action=shop">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/shop.gif" alt="' . $txt[80] . '" border="0" />' : $txt[469]), '</a>', $context['menu_separator'];
echo '
                                <a href="', $scripturl, '?action=arcade">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/games.gif" alt="' . $txt[82] . '" border="0" />' : $txt[471]), '</a>', $context['menu_separator'];
//THIS IS THE CODE
echo'
<a href="javascript:" onclick="window.open(\'http://www.mylinkcom/forum/my_player/myplayer_003.html\'), \'width=200,height=150\');  return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/player.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];
//END CODE

        // The [calendar]!
if ($context['allow_calendar'])
echo '
<a href="', $scripturl, '?action=calendar">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/calendar.gif" alt="' . $txt['calendar24'] . '" border="0" />' : $txt['calendar24']), '</a>', $context['menu_separator'];

// If the user is a guest, show [login] and [register] buttons.
if ($context['user']['is_guest'])
{
echo '
<a href="', $scripturl, '?action=login">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/login.gif" alt="' . $txt[34] . '" border="0" />' : $txt[34]), '</a>', $context['menu_separator'], '
<a href="', $scripturl, '?action=register">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/register.gif" alt="' . $txt[97] . '" border="0" />' : $txt[97]), '</a>';
}
// Otherwise, they might want to [logout]...
else
echo '
<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/logout.gif" alt="' . $txt[108] . '" border="0" />' : $txt[108]), '</a>';
}
?>


that's how it is in my index.template.php file. the code i am trying to work out is attached to one of the buttons on my main menu that's why i can't use the function thing it needs to be in the code or something i dunno it's making me go grey please help

kegobeer

In index.template.php, find

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />
<meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js"></script>
<script language="JavaScript" type="text/javascript"><!--
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
// --></script>
<title>', $context['page_title'], '</title>';


replace with

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />
<meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js"></script>
<script language="JavaScript" type="text/javascript"><!--
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
// --></script>
<script type="text/javascript">
<!--
var newwindow;
function poptastic(url)
{
newwindow=window.open(url,\'name\',\'height=200,width=150\');
if (window.focus) {newwindow.focus()}
}
// -->
</script>
<title>', $context['page_title'], '</title>';


wherever this is

//THIS IS THE CODE
echo'
<a href="javascript:" onclick="window.open(\'http://www.mylinkcom/forum/my_player/myplayer_003.html\'), \'width=200,height=150\');  return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/player.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];
//END CODE


replace with

echo '
<a href="javascript:poptastic(\'' , $scripturl , '?action=admin\');">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin.gif" alt="' . $txt[2] . '" border="0" />' : $txt[2]), '</a>', $context['menu_separator'];
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

scrawl

cheers for taking the time to help me kegobeer. it's much appreciated.

kegobeer

"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Advertisement: