SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    location.href not working

    Have a simple javascript onClick that won't seem to work.

    PHP Code:
    <a href="javascript:;" onClick="window.location.href='page.htm'">Add Another Insert</a
    When you click on the link nothing happens. What am I doing wrong?


    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    link

    I'm confused as to what you're trying to do. You want the browser to go to another page when it's clicked? You don't need javascript for that.
    Are you thinking of "wndow.open"? Or do you have a frame named "window"?

  3. #3
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    of corse that wont work because you set the href to "javascript:" this is sometimes fired insted of onClick. what you should use is:

    HTML Code:
    <a href="#" onClick="window.location.href='page.htm';return false">Add Another Insert</a>
    but like Mittineague said, you are probably trying to open a new window... why would you require javascript on a page if you dont need too? also this is commonly not search engine friendly.

    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A shorter version of that link that would work even more often would be:

    <a href="page.htm">Add Another Insert</a>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am attempting to hide the link with the javascript.

    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.


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
  •