0

I am updating some jQuery code and i need to add "target="_blank"" to the links in the code below. Unfortunately I am not that into jQuery and have not written the original code myself. Thanks in advance for any kind of help!

This is what the code looks like:

<script>

        var console = {log:function(){}}
        var _frames;
        var _activeLink=0;
        var _links = 
        [
            "http://www.transavia.com/hv/main/nav/processflightqry?toDay=23&toMonth=2014-07&lang=fr&adults=1&from=ORY&fromMonth=2014-07&to=MAD&country=FR&infants=0&children=0&fromDay=16&opensearchform=true&tab=cal",
            "http://www.transavia.com/hv/main/nav/processflightqry?toDay=23&toMonth=2014-04&lang=fr&adults=1&from=ORY&fromMonth=2014-04&to=PRG&country=FR&infants=0&children=0&fromDay=16&opensearchform=true&tab=cal",
            "http://www.transavia.com/hv/main/nav/processflightqry?toDay=23&toMonth=2014-04&lang=fr&adults=1&from=ORY&fromMonth=2014-04&to=SAW&country=FR&infants=0&children=0&fromDay=16&opensearchform=true&tab=cal",
            "http://www.transavia.com/hv/main/page?id=destinations&lang=fr&country=FR"
        ]
        $(document).ready(function()
        {

            $(window).load(function()
            {
                resetPrice();
                // start the banner //
                _frames = ["trip1","trip2","trip3","lastFrame"];
                for(var i = 0;i<_frames.length;i++)
                {
                    $("#"+_frames[i]).css({opacity:0})
                }
                //$("#lastFrame").css({opacity:0})
                animate();

                $("#cover").click(function()
                {
                    gotoActiveLink();
                })


            })

            function gotoActiveLink()
            {
                console.log("active link",_activeLink);
                window.location.href = _links[_activeLink]
            }


        })

        </script>
2
  • Go through it and see what it does first. Commented Jun 21, 2014 at 11:04
  • Note: You do not need $(window).load inside $(document).ready() unless you are waiting for images to load completely too (which can take a lot longer than initial page load). Commented Jun 21, 2014 at 11:47

2 Answers 2

2

.attr() can add, get (value) & modify elements attributes

$('a').attr('target', '_blank');

Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately my code doesn't seem to generate any <a>-tag, so I can't get this to work. But Thanks anyway!
1

You are trying to open new windows, rather than using links, so you need to use window.open() instead of just changing the current browser window URL with window.location.

Details here: http://www.w3schools.com/jsref/met_win_open.asp

It includes options for the target type (like "_blank", which also happens to be the default).

  • _blank - URL is loaded into a new window. This is the default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
  • _top - URL replaces any framesets that may be loaded
  • name - The name of the window (Note: the name does not specify the title of the new window)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.