A way to find out if user is in edit mode with Javascript?

Vote:
 

Hi!

I've run into a little problem. I would need to disable a surtain line of Javascript only when a user is in edit mode. It has to do with web browser size and page reloads... Is there a way to find out if a user is in edit mode with/from Javascript? If so I see a good chance of fixing this. Thankful for help!

#132837
Aug 19, 2015 11:18
Vote:
 

Hi,

When editor is logged to edit mode then window object contains "epi" property.

So maybe using:

if (window.epi)
{

    // turn of functionality

}

could help to solve your problem.

#132845
Aug 19, 2015 12:25
Vote:
 

Sweet! That might solve it... Many thanks!

#132846
Aug 19, 2015 12:36
Vote:
 

Hi,

Now I think that maybe a better aproach would be to use "EPiServer.Editor.PageEditing.PageIsInEditMode" value. In previous solution the Javascript checking would be executed every time even if you are not in edit mode. So I think that it will be better to prepare a server condition:

@if (EPiServer.Editor.PageEditing.PageIsInEditMode == false)
{
    <script type="text/javascript">
       // run custom renderring
    </script>
}

Now when the page will be renderred in view mode there will be no exra JS condition.

And also when you use window.epi then it's easy to guess that this is based on EPiServer. In the second solution this information is not available.

#132875
Aug 19, 2015 20:42
Vote:
 

Hi again!

The script will only be run once the browser window is resized... so it's okay in this case. Thanks anyway!

#132895
Aug 20, 2015 14:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.