Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Javascript Help needed!

    Hello!

    I am having some major trouble with a page on a website. The page is:

    http://medresultsnetwork.com/preferred-vendors/

    Essentially, the problem is this. When you click on a logo, you get sent to a website. It opens it up on the current browser window and doesn’t open it up on a new browser window (usually, this is done with target=”_blank”). Ordinarily I would use that target=”_blank” code, but it’s programmed with Javascript and I have no idea how to integrate this functionality with the javascript code.

    I believe I found the function defined here:

    <script type="text/javascript">
    function chngurll(url) {
    window.location.href=url;

    }
    </script>

    And as an example, an instance of where there function is called here:

    <div onclick="chngurll('http://www.laserrepairnetwork.com/')" style="cursor: pointer;" class="pref_cont_main_right_in_part2_box_inner">
    <img width="229" height="122" alt="LRN Logo" class="attachment-post-thumbnail wp-post-image" src="http://medresultsnetwork.com/wp-content/uploads/2013/09/LRN-Logo.png">
    </div>

    Each logo has this code (though with a different picture and URL). I’d be very, very grateful if someone can help me out. I have no idea how to make the javascript open the URL in another window.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,474
    Thanks
    6
    Thanked 980 Times in 953 Posts
    What kind of crappy coding is that anyway? Why is there a division and (inline) JS used to open a new site instead of a plain ol’ link? Change the HTML to
    Code:
    <a href="http://www.laserrepairnetwork.com" class="pref_cont_main_right_in_part2_box_inner">
    <img width="229" height="122" alt="LRN Logo" class="attachment-post-thumbnail wp-post-image" src="http://medresultsnetwork.com/wp-content/uploads/2013/09/LRN-Logo.png">
    </a>
    … and you can use the target as you desire (although I generally don’t recommend it since the users should decide themselves whether or not to open a link in a new window).

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Which of the three places (new window, new tab, same tab) web pages open is completely under the browser's owner's control. You can only suggest where it should open in your code and the browser can be set to ignore your suggestion and open it where the browser owner wants it to open.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Where the web page does suggest where a link should open at best it has no effect, at worst it removes one of the visitor's choices (if they don't know how to set their browser to ignore the suggestion) so as to get them really annoyed at the author.

    That's why target was made obsolete in 1997.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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