Javascript in HREF attribute

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernd Liebermann

    Javascript in HREF attribute

    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="openToolW indow()">LinkTe xt</A>
    then the plain source code of my function is loaded into the window.

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

    3) If I use
    <P onClick="openTo olWindow()">Lin kText</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



  • Lasse Reichstein Nielsen

    #2
    Re: Javascript in HREF attribute

    "Bernd Liebermann" <1234@bernd-liebermann.de> writes:
    [color=blue]
    > 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="openToolW indow()">LinkTe xt</A>
    > then the plain source code of my function is loaded into the window.[/color]

    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 <URL:http://jibbering.com/faq/#FAQ4_24>.
    [color=blue]
    > 2) If I use
    > <A HREF="" onClick="openTo olWindow()">Lin kText</A>
    > my function runs correctly, but the original window loads my start page.[/color]

    Yes. You should add "return false" after the call to prevent the normal
    operation of the link. It's in the link above too.
    [color=blue]
    > 3) If I use
    > <P onClick="openTo olWindow()">Lin kText</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.[/color]

    Then style it:
    ---
    <style type="text/css">
    p[onclick] {
    color:blue;
    text-decoration:unde rline;
    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]".
    [color=blue]
    > How would the cracks handle this problem?[/color]

    Return false.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...