Copied to clipboard

Flag this post as spam?

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


  • Jay 416 posts 642 karma points
    Dec 30, 2015 @ 15:34
    Jay
    0

    Detecting Preview mode in Umbraco 7

    Hi All,

    I'm using Umbraco 7.2.4 and was wondering if there's a way to detect if we are in preview mode as in after someone clicked the "Preview" button within umbraco backend?

    I've tried the below Umbraco.Web.UmbracoContext.Current.InPreviewMode but it keeps returning as true all the time.

    Thanks

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 30, 2015 @ 19:43
    Nicholas Westby
    0

    I've tried the below Umbraco.Web.UmbracoContext.Current.InPreviewMode but it keeps returning as true all the time.

    Perhaps you are actually still in preview mode. Note that if you enter preview mode, you can navigate around the site and still be in preview mode, though it may not be apparent. Umbraco indicates you are in preview mode by dropping a cookie in your browser, so you'll stay in preview mode until that cookie is erased.

    There are a couple ways to exit preview mode. One is to click the banner that appears on the top right of ever page when you are in preview mode (that banner may not be apparent depending on if there are styles on your site that interfere with the banner). Also, I believe you can get out of preview mode by clicking on a different content node in the back office.

    For what it's worth, I use InPreviewMode on some of the sites I work with and it works as expected.

  • Jay 416 posts 642 karma points
    Jan 04, 2016 @ 10:19
    Jay
    0

    Aha. Tested it seems to be the reason why. Thanks Nicholas.

    I'm still checking to see how do you exit the preview mode (which will delete the preview cookie). I don't have the banner on the top of the site and i've tried clicking on a different node too.

    Kind of weird to ask the user to kill their cookie. I'll try to search around the forum as well.

  • Jay 416 posts 642 karma points
    Jan 04, 2016 @ 10:49
    Jay
    0

    I had a checked on the latest Umbraco 7.3.4 and there's a close button for the preview within the left panel (where you've got all the different devices option).

    I've grabbed the codes amend along with the JS amend for the exit button and it works like a charm

    So you have to edit both files within:
    1. Umbraco\preview\index.html
    2. Umbraco\js\canvasdesigner.panel.js

Please Sign in or register to post replies

Write your reply to:

Draft