SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Browser created button in <Anchor> with IE>?

    Anyone know of a way to get IE to draw a clickable, workable button within an anchor tag?

    <A HREF="javascript:[function]" TITLE="Click Button">
    <BUTTON>Click this Button</BUTTON>
    </A>

    This seems to work in Netscape and Firefox but not in IE. The button shows but clicking it does nothing in IE as opposed to Netscape where the javascript function fires.

    I've tried numerous approaches, putting the button within a <FORM></FORM> set, etc. Nothing seems to work in IE; all work in Netscape (have not tested all for Firefox).

    <A HREF="javascript:[function]" TITLE="Click Button">
    <FORM METHOD="link"><INPUT TYPE="submit", VALUE="Click this button"></FORM>
    </A>

    Currently the only way I can seem to get this to work is to create an image of the button and use...

    <A HREF="javascript:[function]" TITLE="Click Button">
    <IMG SOURCE="button.png" BORDER="0">
    </A>

    But making a picture of every button is tiring and not nearly as flexable, also the button does not highlight when you move over it as a generated button will.

    Why can't Microsoft start charging for IE so everyone would switch to Firefox!

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you're going to want to do is put a span inside the anchor, give the span a class of "button" and then style the span to look like a button.

    Why can't Microsoft start charging for IE so everyone would switch to Firefox!
    They already do. It's called purchasing Windows. In fact, Internet Explorer 7 will not run unless you have a valid (read: "Genuine") copy of Windows XP or Vista (when Vista comes out, anyway).

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have three choices:
    1. Use an <input type="button"> (or type="submit") and style it to look like a link anchor.
    2. Use an anchor and style it to look like a button.
    3. Use <button><a href="...">Click this button</a></button>
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    If you're running javascript from the link click, you might as well drop the anchor altogether:

    <button onclick="myFunction();">Click me!</button>

  5. #5
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onclick="window.location=this.href;"

    <a href=xyz" onclick="window.location=this.href;">
    <input type="button" value="click me"/>
    </a>

    I believe this works for IE, because when you put an image inside an anchor,
    IE will respond to onclicks, but not to hrefs!

    Stewart
    London, UK


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •