0

I'm creating a site for a client who needs to use a zip code to search for a provider but the search is on a provider search website that's not within our domain. I need to modify this script to be able to force it to open in a new window.

<script type="text/javascript">
    $(document).ready(function () {
        var submitVetSearchD = function () {
            submitVetSearch($('#zip'));
        }

        function submitVetSearchM() {
            submitVetSearch($('#zipM'));
        }

        function submitVetSearchF() {
            submitVetSearch($('#zipF'));
        }

        function submitVetSearch(ele) {
            var zipval = ele.val();
            var url = 'https://www.fakesearchresultswebsite.com/';
            if (zipval !== "") {
                return window.location.href = url + '?zip=' + zipval;
            }
        }

        $("#zip").keyup(function (event) {
            if (event.keyCode == 13) {
                submitVetSearchD();
            }
        });
        $('#large-header-vet-search').click(submitVetSearchD);

        $("#zipM").keyup(function (event) {
            if (event.keyCode == 13) {
                submitVetSearchM();
            }
        });
        $('#mob-vet-search').click(submitVetSearchM);

        $("#zipF").keyup(function (event) {
            if (event.keyCode == 13) {
                submitVetSearchF();
            }
        });
        $('#footer-vet-search').click(submitVetSearchF);

        $("a[rel^='prettyPhoto']").prettyPhoto();

        //top menu size
        $(window).resize(function () {
            setTopMenuHeight();
        });

        setTopMenuHeight();

        var smallHeader = false;
        var menuBig = true;

        $(document).scroll(function () {
            var ele = $("#top-menu-height");
            var menuBigNew = !(ele.is(":visible") && $(window).scrollTop() > 200);

            if (menuBig != menuBigNew && smallHeader) {
                menuBig = menuBigNew;

                $("#navtop").toggleClass("small-page-header");
                $(".fixed-top").toggleClass("pos-fix");
                $("#page-header").toggleClass("fixed-header");
                $("#title-area").toggleClass("title-area-small");

                $("#logo1").finish();
                $("#logo2").finish();
                $("#top-menu").finish();

                if (menuBig) {
                    $("#logo2").toggle();
                    $("#logo1").toggle(1000);
                } else {
                    $("#logo1").toggle();
                    $("#logo2").toggle(1000);
                }

                //$("#top-menu").fadeToggle();
            }
        });

        //$('body').on('open.fndtn.reveal', function(){
        //    $('body').css('overflow', 'hidden');
        //});

        //$('body').on('closed.fndtn.reveal', function(){
        //    $('body').css('overflow', 'visible');
        //});
    });

    function setTopMenuHeight() {
        var ele = $("#top-menu-height");
        var height = $("#page-header").height();
        ele.height(height);
    }
</script>
1

1 Answer 1

1

Replace

return window.location.href = url + '?zip=' + zipval;

with

var newWin = window.open(url + '?zip=' + zipval);
return true;

Declare newWin in the global scope, it will reference the new window.

Reference: http://www.w3schools.com/jsref/met_win_open.asp

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.