为什么我的函数不使用window.location.href进行重定向?

时间:2019-12-05 17:17:36

标签: javascript cookies

我有一个javascript函数链接到一个表单,该表单检查cookie并登录,因此当它执行所有检查并且一切正常时,它会显示一个确认弹出窗口,如果用户单击确定,则应链接到另一个内部页面但是,我的意思是,它没有显示确认弹出窗口,但没有重定向。 我已经尝试了window.location.href和window.location.replace,但是没有用。

function checkCookies() {





    var emailValue = document.getElementById("nombre").value;

      var passValue = document.getElementById("pass1").value;


      var correct_email = checkCookie("email", emailValue);
      var correct_pass = checkCookie("pass", passValue);

      if (correct_email == -1) {
        alert("Password or email are wrong")
      } else if (correct_pass == -1) {
        alert("Password or email are wrong")

      } else if (correct_pass === correct_email) {
        alert("Log in succesfully")
        window.location.href = "principal.html";
      } else {
        alert("Password or email are wrong")
      }
    }

2 个答案:

答案 0 :(得分:0)

如果看到

  

成功登录

在屏幕上,然后什么也没有发生,请尝试替换此行:

window.location.href = "principal.html";

使用

location.assign("/principal.html");

我假设/principal.html与我们在检查Cookie或根目录时所处的目录相同。

答案 1 :(得分:0)

尝试

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp 
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" 
  xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" 
  xsi:type="MailApp">


  <!-- IMPORTANT! Id must be unique for your add-in, if you reuse this manifest ensure that you change this id to a new GUID. -->
  <Id>d0aa58bd-1618-45ed-a773-9e8353a85215</Id>

  <Version>1.0.0.0</Version>
  <ProviderName>Test Name</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Onvio Add-In" />
  <Description DefaultValue="Onvio Outlook Add-In For Interaction With Document Management Service"/>
  <IconUrl DefaultValue="https://img.icons8.com/clouds/2x/cloud-network.png" />
  <HighResolutionIconUrl DefaultValue="https://d1nhio0ox7pgb.cloudfront.net/_img/g_collection_png/standard/256x256/earth.png" />


 <SupportUrl DefaultValue="https://localhost:4200"/>
  <!--End Basic Settings. -->

  <Hosts>
    <Host Name="Mailbox" />
  </Hosts>
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.1" />
    </Sets>
  </Requirements>
  <FormSettings>
    <Form xsi:type="ItemEdit">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://localhost:4200"/>
      </DesktopSettings>
    </Form>
  </FormSettings>

  <Permissions>ReadWriteItem</Permissions>
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
  </Rule>
  <DisableEntityHighlighting>false</DisableEntityHighlighting>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Resources>
      <bt:Images>
        <bt:Image id="Onvio.PaneButton.Icon" DefaultValue="https://i.imgur.com/FkSShX9.png" />
      </bt:Images>
      <bt:Urls>
        <bt:Url id="Onvio.FunctionFile.Url" DefaultValue="https://localhost:4200" />
        <bt:Url id="Onvio.Taskpane.Url" DefaultValue="https://localhost:4200" />
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="Onvio.Pane.Title" DefaultValue="Onvio Side Panel" />
        <bt:String id="Onvio.Pane.Label" DefaultValue="Show Taskpane" />
        <bt:String id="Onvio.Tab.Label" DefaultValue="Onvio Tab Label" />
        <bt:String id="Onvio.OpenedMessageTools.Label" DefaultValue="Onvio.OpenedMessageTools.Label" />
        <bt:String id="Onvio.ComposeMessageTools.Label" DefaultValue="Onvio.ComposeMessageTools.Label" />
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="Onvio.Pane.Description" DefaultValue="Onvio Side Panel Description" />
      </bt:LongStrings>
    </Resources>
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <Description resid="residDescription" />
      <Requirements>
        <Sets xmlns="http://schemas.microsoft.com/office/officeappbasictypes/1.0">
          <Set Name="Mailbox" MinVersion="1.1" />
        </Sets>
      </Requirements>
      <Hosts>
        <Host xsi:type="MailHost">
          <DesktopFormFactor>
            <ExtensionPoint xsi:type="MessageComposeCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="Message" xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1">
                  <Label resid="Onvio.ComposeMessageTools.Label" />

                  <Control xsi:type="Button" id="Onvio.ComposePane.Button">
                    <Label resid="Onvio.Pane.Label" />
                    <Supertip>
                      <Title resid="Onvio.Pane.Title" />
                      <Description resid="Onvio.Pane.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Onvio.PaneButton.Icon" />
                      <bt:Image size="32" resid="Onvio.PaneButton.Icon" />
                      <bt:Image size="80" resid="Onvio.PaneButton.Icon" />
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Onvio.Taskpane.Url" />
                      <SupportsPinning>true</SupportsPinning>
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>
            <ExtensionPoint xsi:type="MessageReadCommandSurface">
              <CustomTab id="Onvio.OpenedMessageTools.Tabs">
                <Group id="Onvio.OpenedMessageTools.Group" xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1">
                  <Label resid="Onvio.OpenedMessageTools.Label" />
                  <Control xsi:type="Button" id="Onvio.Pane.Button">
                    <Label resid="Onvio.Pane.Label" />
                    <Supertip>
                      <Title resid="Onvio.Pane.Title" />
                      <Description resid="Onvio.Pane.Description" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Onvio.PaneButton.Icon" />
                      <bt:Image size="32" resid="Onvio.PaneButton.Icon" />
                      <bt:Image size="80" resid="Onvio.PaneButton.Icon" />
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Onvio.Taskpane.Url" />
                      <SupportsPinning>true</SupportsPinning>
                    </Action>
                  </Control>
                </Group>
                <Label resid="Onvio.Tab.Label" />
              </CustomTab>
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>

还有,您遇到什么错误?