Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link target problem

Status
Not open for further replies.

sfenx

Programmer
Feb 23, 2001
81
BE
I have an image used as a button that opens another window. The problem is I want that page to be opened in another (new) window. In my code the "window.location.target" doesn't work.

Code:
<img src=&quot;h_link-arrow.gif&quot; onClick=&quot;window.location.target='_blank';window.location.href='linkpage.asp';&quot;>

thnx,
Sfenx
 
Use an HREF...

<a href=&quot;linkPage.asp&quot; target=&quot;_blank&quot; border=0>
<img src=&quot;h_link-arrow.gif&quot;>
</a> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Sfenx,

I am still new to JavaScript, but this seemed to work for me.

<img src=&quot;h_link-arrow.gif&quot; onClick=&quot;window.open('linkpage.asp');&quot;>

I hope this is what you were looking for.


!ThisGuy


 
Sorry, disregard my post. I misread your question.

!ThisGuy
 
mwolf00,
The reason I don't use your solution is that I need a variable to go along with the url, and this variable I'm getting from a dropdownlist (so different values are possible). I really need the target attribute to work in the onClick-event.

Code:
<img src=&quot;h_link-arrow.gif&quot; onClick=&quot;var level=document.compform.gencomp.options[document.compform.gencomp.selectedIndex].value;window.location.target='_blank';window.location.href='linkpage.asp?level='+level;&quot;>
 
I don't believe that the location object has a target. I suggest a javascript function then...

<script>
function newPage(){
thisVal = document.myForm.mySelect.options(document.myForm.mySelect.selectedIndex).value
window.open(&quot;linkPage.asp?level=&quot; + thisVal)
}
</script>

<img src=&quot;h_link-arrow.gif&quot; onClick=&quot;newPage()&quot;>

alternate version....
<script>
function newPage(){
newWin = window.open(&quot;&quot;)
document.myForm.action = &quot;linkPage.asp&quot;
document.myForm.target = newWin
document.myForm.submit()
}
</script>
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top