Javascript in HREF attribute

  • Thread starter Bernd Liebermann
  • Start date
B

Bernd Liebermann

Hi,

I need some help on a simple question: I have a link that should open a new
window (no action in main window), which is realized by a function that
calls window.open(). The function itsself works fine, but here is the
problem:

1) If I use
<A HREF="openToolWindow()">LinkText</A>
then the plain source code of my function is loaded into the window.

2) If I use
<A HREF="" onClick="openToolWindow()">LinkText</A>
my function runs correctly, but the original window loads my start page.

3) If I use
<P onClick="openToolWindow()">LinkText</P>
everything works like intended except that my paragraph does not behave like
a normal hypertext reference, i.e. it is not undelined, has a different
color, and the mousecursor does not change into the "hand"-cursor on
mouseover.

How would the cracks handle this problem? The document in the main window
should not be reloaded, if possible. It is a php-script that performs some
database action, and I want to keep the workload low for my server.

Best regards,
Bernd
 
L

Lasse Reichstein Nielsen

Bernd Liebermann said:
I have a link that should open a new window (no action in main
window), which is realized by a function that calls
window.open(). The function itsself works fine, but here is the
problem:

1) If I use
<A HREF="openToolWindow()">LinkText</A>
then the plain source code of my function is loaded into the window.

Surpricing. I would have expected a "page not found" error. Do you mean
with "javascript:" in front? And did you forget the parentheses?

In any case, forget it.
Read said:
2) If I use
<A HREF="" onClick="openToolWindow()">LinkText</A>
my function runs correctly, but the original window loads my start page.

Yes. You should add "return false" after the call to prevent the normal
operation of the link. It's in the link above too.
3) If I use
<P onClick="openToolWindow()">LinkText</P>
everything works like intended except that my paragraph does not behave like
a normal hypertext reference, i.e. it is not undelined, has a different
color, and the mousecursor does not change into the "hand"-cursor on
mouseover.

Then style it:
---
<style type="text/css">
p[onclick] {
color:blue;
text-decoration:underline;
cursor:pointer;
}
</style>
---
You should probably give it a class, because IE doesn't understand CSS 2,
so it won't understand the attribute selector "p[onclick]".
How would the cracks handle this problem?

Return false.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top