Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Firefox JS Redirects not working.

Options
  • 11-04-2012 5:21pm
    #1
    Registered Users Posts: 3,992 ✭✭✭


    Ok so im redirecting to a new page after a button is clicked.

    This works fine in IE & Chrome but won't in Firefox
    window.location.href = ("../../Default.aspx");
    

    In Firefox, it just hangs on a white screen with the address in the address bar.

    If I highlight the address bar and hit enter (or refresh) it loads properly.

    It just seems to stop executing after the code behind has finished running. No errors there either.

    Anyone got any Ideas as to what might be happening ?

    I've tried other variations on the redirect

    top.location.href = "../../Default.aspx";
    window.open("../../Default.aspx");
    parent.top.location.href=('../../Default.aspx');
    location.replace('../../Default.aspx');


Comments

  • Closed Accounts Posts: 249 ✭✭OneIdea


    Try instead
    window.location.href = '../../Default.aspx';
    

    Without brackets and double quotes...


  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    window.location = 'url', this should map to location or .href depending on the browser. It's an annoying one anyway!


  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    Hmm, No joy with that either...

    Its a .Net site with a C# code-behind. I notice that the code-behind of the file im trying to get to is executing. But the client side (JS etc) isn't.


  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    Ctrl+Shift+J, select "Clear", then hit the button. What error shows up? If you use an absolute URL, does that work? i.e. window.location.href = ("http://www.google.ie");

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    Back onto this now.
    28064212 wrote: »
    Ctrl+Shift+J, select "Clear", then hit the button. What error shows up? If you use an absolute URL, does that work? i.e. window.location.href = ("http://www.google.ie");

    No errors show up at all.

    The codebehind of my "Default.aspx" is firing grand:
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Set the browser name and major version for cross-browser support.
            Session["Browser"] = String.Format("{0}{1}", Request.Browser.Browser, Request.Browser.MajorVersion.ToString());
            //Store the TS (Touchscreen) session, used when users are working on a touchscreen.
            Session["TS"] = Request.Path.ToLower().Contains(ConfigurationManager.AppSettings["TOUCHSCREENVD"].ToLower()) ? "1" : "0";
        }
    }
    

    But the Javascript isn't firing at all...
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <body>
    
        <script type="text/javascript" language="javascript">
            alert('HERE');
            //top.location.href = "./Console/CMServices.aspx";
            //top.location.href = "./Console/CCServices.aspx";
            if ('<%=Session["TS"]%>' == "1") {
                window.open("VTLogin.aspx?m=1", 'TheNewpop', 'fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
            }
            else {
                window.location.href = 'VTLogin.aspx?m=0';
                //top.location.href = "VTLogin.aspx?m=0";
                //top.location.href = "../../Default.aspx";
                //window.open("../../Default.aspx");
                //parent.top.location.href = ('../../Default.aspx');
                //location.replace('../../Default.aspx');
            }
        </script>
    
    </body>
    </html>
    


  • Advertisement
  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    Put this in the head of default.aspx:
    <script type="text/javascript" language="javascript">
    function test(){
    alert("test");
    }
    </script>
    
    And change the body tag to this:
    <body onload="test()">
    

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    Nope, its not displaying anything. I stuck an alert("test"); in the header aswell, no joy.

    Here's what happens when I start the program:

    Default.aspx
    loads and decides if the user is on a touch screen or a normal desktop
    > redirect to >
    Login.aspx - displays differently depending on if user is on desktop or touchscreen. (on page keypad etc for TS)
    User logs in. .
    > redirect to >
    Clock.aspx
    User clocks in or out. (presses a button, Login/Logout, this calls some sql that clock the user out.)
    > redirect to >
    Default.aspx

    Now this all works fine in IE and Chrome.

    But in FF, when it gets to Default.aspx at the end, it loads the c# code behind. (Default.aspx.cs, Setting some session variables) But then nothing happens after that. The window stays blank with "localhost:61146/Default.aspx" in the address bar (i'm testing locally, this happens when the site is deployed too)


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    I've just run the code provided here and it's working on my version of Firefox (11.0).
    I had to change the markup as follows though:

    Where you have
    [PHP]<head>
    </head>[/PHP]
    I had to change it to
    [PHP]<head runat="server">
    </head>[/PHP]
    Without that I got
    Server Error in '/' Application. Using themed css files requires a header control on the page. (e.g. <head runat="server" />).


  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    It runs fine when it is initially called. But when I am trying to redirect back to it it does not work.

    Adding runat didnt work.


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Is it in the spec that you have to support Firefox? ;)


  • Advertisement
  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    Malice wrote: »
    Is it in the spec that you have to support Firefox? ;)

    We don't usually support it.

    I've been asked to look into it today and tomorrow...

    If i cant fix it then i cant fix it, they will have to use IE...

    Id rather get it sorted than waste 2 days on it though :P.. Ah well.... :pac:


  • Registered Users Posts: 3,992 ✭✭✭Korvanica


    Solved it.

    Turns out Firefox doesn't like the "onunload" method.

    Replacing this with onbeforeunload fixes the issue.


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Glad you got it sorted. I vaguely recall having to work around this issue before, I think we just re-jigged some stuff and ended up calling a Response.Redirect on the server side. I had this bookmarked on StackOverflow which might be of some help.


Advertisement