Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:08:21+00:00 2026-06-13T12:08:21+00:00

Regarding the browser version, the player height should change if older then ie9 //height

  • 0

Regarding the browser version, the player height should change

if older then ie9 
  //height is fixed
else 
  //height is auto

The above code is working but, it’s the worst thing I’ve seen, because I do repeat myself again and again, when only one line changes on this conditional.

<script type="text/javascript"> 
    $(document).ready(function() {

        if ($.browser.msie && $.browser.version.substr(0,1)<9) {
            $("#jquery_jplayer_1").jPlayer({
            ready: function () 
            {
                $(this).jPlayer("setMedia", 
                {
                    m4v: "/video/videoK.mp4",
                    ogv: "/video/videoK.ogg"
                }).jPlayer("play");

                $('article.about-k').hide();
                olark('api.box.hide');
            },
            swfPath: "/scripts/",
            supplied: "m4v, ogv",
            size: {
                width: "100%",
                height: "400px" // THE ONLY CHANGE IS HERE
            },
            backgroundColor: "#fff",
            click: function() {
                $(this).jPlayer("play");
            },
            ended: function() {
                $('.jplayer-k').hide();
                $('article.about-k').show();
            }
        })
      } else {
        $("#jquery_jplayer_1").jPlayer({
            ready: function () 
            {
                $(this).jPlayer("setMedia", 
                {
                    m4v: "/video/videoK.mp4",
                    ogv: "/video/videoK.ogg"
                }).jPlayer("play");

                $('article.about-k').hide();
                olark('api.box.hide');
            },
            swfPath: "/scripts/",
            supplied: "m4v, ogv",
            size: {
                width: "100%",
                height: "auto" // THE ONLY CHANGE IS HERE
            },
            backgroundColor: "#fff",
            click: function() {
                $(this).jPlayer("play");
            },
            ended: function() {
                $('.jplayer-k').hide();
                $('article.about-k').show();
            }
        })
      }

    });
</script>

As noted by the comments, the only change is on ONE single line.
How can I remake this, without stupidly repeating myself ?

 height: "auto" //THIS IS THE ONLY DIFFERENCE!

Please advice

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:08:22+00:00Added an answer on June 13, 2026 at 12:08 pm

    That’s quite simple with a ternary operator:

    $("#jquery_jplayer_1").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                m4v: "/video/videoK.mp4",
                ogv: "/video/videoK.ogg"
            }).jPlayer("play");
    
            $('article.about-k').hide();
            olark('api.box.hide');
        },
        swfPath: "/scripts/",
        supplied: "m4v, ogv",
        size: {
            width: "100%",
            height: ($.browser.msie && $.browser.version.substr(0, 1) < 9)
              ? "400px"
              : "auto"
        },
        backgroundColor: "#fff",
        click: function () {
            $(this).jPlayer("play");
        },
        ended: function () {
            $('.jplayer-k').hide();
            $('article.about-k').show();
        }
    })
    

    If you don’t like that (e.g. because of a more complex condition), you still can use a simple variable:

    var height = "auto";
    if (/* IE too old */)
        height = "400px";
    $…({
          … // huge config object
          height: height,
          …
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an issue regarding jQuery.noConflict with I.E. browser version 7, version 8, and
I have a problem relate to my TextOnly Browser for Android regarding browser in
I have question regarding disabling browser caching. I have already found few solutions, and
Regarding: http://code.google.com/chrome/extensions/idle.html Is thresholdSeconds : 1) insisting that the callback is only called if
Does anyone have any updated stats regarding browser support for CSS3 vs CSS2? There
i want to display my webpage in all the browser versions...my code is working
I've been reading about problems people are having with browsers caching an old version
My Flash designer is reading an XML stream I'm sending back to the browser
Regarding the ASP.NET Universal Providers (System.Web.Providers), do they automatically offer the retry logic when
Regarding the regexp in TCL, if I use the following regexp: regexp helloworld\[\\s]+.name. to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.