Results 1 to 8 of 8

Thread: javascript window.location.href doesn´t fire

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    13

    javascript window.location.href doesn´t fire

    Hi,

    Recently, I´ve had to update some code due to some "upgrade" I guess.

    I changed window.navigate to window.location.href where it was needed, and it worked for most cases.

    However, there is one that doesn´t work. I´ve placed an alert after it and it displays correctly, so it´s not that the code aborts.

    I hope this is a known issue. The function is being called from another function. The code is placed directly in the .aspx for the moment.

    Thanks!
    Fabean
    Code:
     window.location.href = "www.google.com"
    alert("klart");

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: javascript window.location.href doesn´t fire

    What browsers are you testing with?

    Try adding http:// in your href value.

    Code:
    window.location.href = 'http://www.google.com';
    Last edited by KGComputers; Feb 28th, 2017 at 10:31 AM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    13

    Re: javascript window.location.href doesn´t fire

    Thanks for answering,

    I´ve tried with chrome and firefox.

    I´ve also tried a number of different url:s, but the line simply doesn´t execute. The following alert executes though.

    Fabean

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: javascript window.location.href doesn´t fire

    You need to include the http:// otherwise it will try to use it as a relative part rather than an absolute.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: javascript window.location.href doesn´t fire

    Have you tried the suggested fix in post #2 (adding http:// to the url)?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    13

    Re: javascript window.location.href doesn´t fire

    Quote Originally Posted by KGComputers View Post
    Have you tried the suggested fix in post #2 (adding http:// to the url)?
    Yes, I did. Both with and without. All kinds of adresses.

    However I should say that I am testing locally it locally.

    Fabean

  7. #7
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: javascript window.location.href doesn´t fire

    I´ve placed an alert after it and it displays correctly, so it´s not that the code aborts.
    Remove the alert(s) statement(s) following window.location.href statement. I tested the suggested fix in Firefox, Chrome and IE10.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: javascript window.location.href doesn´t fire

    Oh, also it only works (I believe) if you access it via a server address... even if iti's http://localhost/test.html if you're double-clicking an html, then the rules change...

    I know there's some quirky rules regarding changing the href from js code like this... which is why I try to avoid doing so, and opt for doing a meta refresh with the new url.

    Weird that it seems to work sometimes for you, but not in one case.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width