TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 606
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 458
  • Total: 458

javascript Drop Down link table

Started by g6cad, February 04, 2006, 05:38:51 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

qwe3

Quote from: rbh on April 10, 2006, 04:03:22 PM
G6, what i want it to do is open the links in a new window rather then the link opening in the current window taking users away from my site.

Nice job and thanks,  I also want a new window any ideas?

rbh

#11
well, i played around for awhile and finally came out with this. it also includes a go button so the link doesn't load automatically in case people choose the wrong link accidentally.



<script>
<!--
function land(ref, target)
{
lowtarget=target.toLowerCase();
if (lowtarget=="_self") {window.location=loc;}
else {if (lowtarget=="_top") {top.location=loc;}
else {if (lowtarget=="_blank") {window.open(loc);}
else {if (lowtarget=="_parent") {parent.location=loc;}
else {parent.frames[target].location=loc;};
}}}
}
function jump(menu)
{
ref=menu.choice.options[menu.choice.selectedIndex].value;
splitc=ref.lastIndexOf("*");
target="";
if (splitc!=-1)
{loc=ref.substring(0,splitc);
target=ref.substring(splitc+1,1000);}
else {loc=ref; target="_blank";};
if (ref != "") {land(loc,target);}
}
//-->
</script>

<form action="dummy" method="post"><select name="choice" size="1">
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME
<OPTION VALUE="URL">LINK NAME

</select><input TYPE="button" VALUE="GO!" onClick="jump(this.form)"></form>


if you don't want the go button just remove <input TYPE="button" VALUE="GO!" onClick="jump(this.form)">

if you want to have it open in the same window just change the target to self instead of blank in this line        else {loc=ref; target="_blank";};

and if you really want to customize each individual link just copy *_blank after each url changing blank to self or parent depending on how you want the specific links to open, for example, a link to open another part of your forum or webpage would have *_self after the url, while a link to another website would have *_blank after the url.

example <OPTION VALUE="http:///www.yahoo.com*_blank">Yahoo
            <OPTION VALUE="http://www.myforum.com/pictures.htm*_self">Pictures

qwe3

rbh,

Script would not work for me.  I got error on page message at bottom left of main window.

rbh

    you might double check that you are copying everything correctly and that you are putting this code into a scriptbox. i just copied this code and tested it on my site to make sure i had it posted correctly, and it worked.

G6Cad

Make sure you put it in a HTML/Javascript Block (script Block)


Sapphire

This is a great block!

And I realize this is probably "in your face" obvious, but I have a question -
I've tried every way I know of to manually set the width, and none seem to work once I input them into the block.  I want to use several of these drop-downs, but the link titles in each grouping are of varying widths - so they end up appearing staggered.

I'm playing with TP and this script on my test forum if you want to see what I mean:
http://www.soulofadoption.com/testforum/index.php

Thanks for any advice you might have for me.  :)

CM-MN

Your post is still being found useful..... of course ;-)

Thanks for posting this........ it's just what I've been looking for!!!!

This website is proudly hosted on Crocweb Cloud Website Hosting.