Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mads Sørensen 188 posts 433 karma points
    Jan 14, 2016 @ 12:05
    Mads Sørensen
    0

    Server side device detection

    Hi Guys Sorry for maybe putting this in the wrong category.

    I've been searching for a solution to detect wich device my umbraco website is been viewed at.

    Why, because I've a HTML 5 Movie:

    <video autoplay="" loop="" style="">
      <source src="/images/homepage_bg_v2.mp4" type="video/mp4">
      <source src="/images/homepage_bg_v2.webm" type="video/webm">
      <source src="/images/homepage_bg_v2.ogv" type="video/ogv">
    </video>
    

    ...and i only want to load it if the website is visited by an desktop - to get rid of the movie geting loaded on a mobile ore tablet.

    Can some one put in an direction - it would be much appreciated :o)

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 15, 2016 @ 08:57
    Dan Lister
    100

    Hi Mads,

    Something like this might be useful to detect whether your request is visited by a mobile device or not. The following video will only display if the current request is not a mobile device.

    @if (!Request.Browser.IsMobileDevice)
    {
        <video autoplay="" loop="" style="">
            <source src="/images/homepage_bg_v2.mp4" type="video/mp4">
            <source src="/images/homepage_bg_v2.webm" type="video/webm">
            <source src="/images/homepage_bg_v2.ogv" type="video/ogv">
        </video>
    }
    

    I hope that helps.

    Thanks, Dan.

  • Mads Sørensen 188 posts 433 karma points
    Jan 15, 2016 @ 09:34
    Mads Sørensen
    0

    Hi Dan That sounds pretty easy :D

    Is it just basic razor script? And is there som umbraco documentation somewhere?

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 15, 2016 @ 09:39
    Dan Lister
    0

    Hi Mads,

    The property Request.Browser.IsMobileDevice is part of the .NET Framework, rather than being Umbraco specific. It can be used within a view or a controller depending on where you want to perform the detection.

    Thanks, Dan.

Please Sign in or register to post replies

Write your reply to:

Draft