Results 1 to 6 of 6

Thread: IE7 href + onclick - both happen

  1. #1
    Join Date
    Jan 2010
    Posts
    119

    IE7 href + onclick - both happen

    I have a small problem with an HTML page in Internet Explorer 7. The code contains the below script in it:
    HTML Code:
    <p>
    <a href="http:///www.techarena.in/" onclick="window.open('http://www.techarena.in/', 'popup'); return false">Click me</a>
    </p>
    What the problem is that whenever I click on the link, I am taken to a popup window and the new page also moves to the href location behind it. And the href occurs before the onclick event and because of this the onclick return value is not taken into account.

    The awesome part of this code is that it works on others machine but not on mine. I think this may be because of Visual Studio 2005 that I have recenly installed on my computer. But then also I tried resetting Internet Explorer settings, however, it didn't helped any how. I even uninstalled all the toolbars that I have just to make sure if that isn't stopping somehow. But no gain. I have seen using some other browsers on my machine and Firefox and Opera didn't find such problem.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: IE7 href + onclick - both happen

    You could try out by adding the statement return false on your onClick so that the code should halt moving further until you find an error in the code. Can you provide the exact code what you have in your program? Because I think the code, you gave us, is a modified version in order to prevent your code to be displayed on the net. But if you will give us the actual code then that will help us to explain you things in a better way.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: IE7 href + onclick - both happen

    You can do something like this:

    HTML Code:
    <p>
    <a href="#" onclick="window.open('http://www.techarena.in/', 'popup'); return false">Click me</a>
    </p>
    and if it doesn't work in your case then here it is what you have to do:

    HTML Code:
    <script>
    function showWindow(){
    var newWindow = window.open('http://www.techarena.in/', 'popup');
    }
    </script>
    </head>
    <body>
    <p>
    <a href="javaScript:{showWindow()}">Click me</a>
    </p>

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: IE7 href + onclick - both happen

    Yes, you can try the suggestions give above but just remember that the first code will reload your page whereas the second will unload anything that is currently running on the page. To avoid that you can add "void" as shown below:

    HTML Code:
    <a href="javaScript:void(showWindow())">Click me</a>

  5. #5
    Join Date
    Jan 2010
    Posts
    119

    Re: IE7 href + onclick - both happen

    Thanks for your inputs but I am not here to get some alternative solutions. My main concern is why I am getting such kind of behavior with my IE7 and that too on only my current PC. As I said it is working with IE7 on other computer and also on other browser on this computer. Replacing href to # will definitely open the popup window and my launch page will switch to #.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: IE7 href + onclick - both happen

    Your program will work as you code it depending on the connection, content loading etc. In your code, you ask your link to navigate to another page and then there you ask it to load similar content as a popup. When the popup is loaded, you return a false stopping the content load in the same window. The code will work if everything goes according to your thoughts. However you are messing it up since the content is loaded as a popup and during the process the link is already loaded. As you can see in your code, your onclick is doing 2 things at the same time but in different order. I would recommend you to do that using javascript function where you are allowed to order your events.

Similar Threads

  1. Dynamic HREF on onClick
    By hounds in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:53 PM
  2. onClick Submit on link (href)
    By Cortezz in forum Software Development
    Replies: 5
    Last Post: 13-05-2010, 12:14 AM
  3. onClick - change href
    By Neutrals in forum Software Development
    Replies: 6
    Last Post: 12-05-2010, 09:25 AM
  4. A Href And OnClick Button
    By Endowed in forum Software Development
    Replies: 5
    Last Post: 11-05-2010, 10:24 PM
  5. Cancel href via an onclick
    By Doshi1 in forum Software Development
    Replies: 5
    Last Post: 11-05-2010, 10:04 AM

Tags for this Thread

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
  •  
Page generated in 1,713,242,975.58131 seconds with 17 queries