---
schema_version: "1"
id: 3d2dfe318e4985d70fb19e4415fa4b408a3951ade51d1513113f8e660dccd9b2
title: Replace the window.location Method
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/lex_prepare_vf_window.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.lex_prepare_vf_window.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7d4efc260e4b1427728ee17519f0391a9b1ec720a58b0b38cf00f65d45115eca
description: The window.location variable is a JavaScript method used to redirect the browser to a new page. JavaScript code in a Visualforce page that sets window.location directly isn't compatible with Lightning Experience. That's the bad news. The good news is that sforce.one navigation methods do the same thing, and are compatible with Lightning Experience.
products:
  - Salesforce Platform
  - Cross Cloud
release: "264"
---
# Replace the window.location Method

The window.location variable is a JavaScript method used to redirect the browser to a new page. JavaScript code in a Visualforce page that sets window.location directly isn't compatible with Lightning Experience. That's the bad news. The good news is that sforce.one navigation methods do the same thing, and are compatible with Lightning Experience.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Group</strong>, <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d193251e70">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d193251e70 ">To create, edit, or delete Visualforce pages:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d193251e70 ">Customize Application</td>

          </tr>
        </tbody>
      </table>

Because window.location can be used in many ways, it’s not possible to address all of the possibilities. Let’s look at a case where window.location is used as a link to the edit page for an account. Then you can use this example, including the code samples, as a guide for addressing other occurrences of window.location in your pages. If you can determine what your window.location method is trying to do, chances are a sforce.one workaround exists.

1. Locate window.location in the Visualforce code.
    1. From Setup, enter Visualforce in the **Quick Find** box, then select **Visualforce Pages**.
    2. Click **Edit** next to the Visualforce page.
    3. Search the Visualforce markup for the following: window.location.
        
        ```markup
        <apex:page standardController="Account" lightningStylesheets="true">   
          <apex:form >      
            <apex:pageBlock >
              <apex:pageBlockSection title="Edit">
                <apex:commandButton value="Edit" 
                 onclick="window.location='/{!Account.Id}/e'; return false;"/>
              </apex:pageBlockSection>
            </apex:pageBlock>
          </apex:form> 
          <apex:detail />
        </apex:page>
        ```
2. Determine where window.location is redirecting to. You can figure this out by testing the Visualforce page in Salesforce Classic.
3. Find the appropriate [sforce.one method](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/salesforce1_dev_jsapi_sforce_one.htm) to replace window.location.
4. Replace all instances of window.location with sforce.one navigation.
    
    ```markup
    <apex:page standardController="Account" lightningStylesheets="true">   
      <apex:form >    
        <apex:pageBlock >
          <apex:pageBlockSection title="Edit">
            <apex:commandButton value="Edit" 
             onclick="sforce.one.editRecord('{!Account.Id}');"/>
          </apex:pageBlockSection>
        </apex:pageBlock>
      </apex:form>    
      <apex:detail />
    </apex:page>
    ```
5. Save your changes.
6. If your Visualforce page is going to be accessed in both Salesforce Classic and Lightning Experience, make both options available. Use an if statement to branch the code.
    
    ```markup
    <apex:page standardController="Account" lightningStylesheets="true">  
       <script>
         function isLightningExperience(){
            if (UITheme.getUITheme() === 'Theme4d' || UITheme.getUITheme() === 'Theme4u'){
                sforce.one.editRecord('{!Account.Id}');
            } else {
                window.location='/{!Account.Id}/e';
            }
        }
       </script>     
       <apex:form >    
         <apex:pageBlock >
           <apex:pageBlockSection title="Edit">
             <apex:commandButton value="Edit" 
              onclick="javascript:isLightningExperience();return false;"/>
           </apex:pageBlockSection>
         </apex:pageBlock>
       </apex:form>    
       <apex:detail />       
    </apex:page>
    ```