window.location not working

Discussion in 'Javascript' started by Craig Keightley, Mar 14, 2005.

  1. I have a very simple confirm link on a website using the following code:

    function confirmNewSupplier(){
    if(confirm(' Are you sure that you can\'t select a supplier from the
    list? \n(Click OK to request a new supplier or Cancel to return to the
    Directory)')){
    window.location = 'l1stage1.php';
    }
    }


    the link is as follows:

    <a href="javascript:;" onClick="confirmNewSupplier()"
    class="mainTextNormal">Creating a New Supplier</a>

    The alert pops up but it does not redirect

    What am i doing wrong???
     
    Craig Keightley, Mar 14, 2005
    #1
    1. Advertising

  2. Craig Keightley wrote:

    > the link is as follows:
    >
    > <a href="javascript:;" onClick="confirmNewSupplier()"
    > class="mainTextNormal">Creating a New Supplier</a>
    >
    > The alert pops up but it does not redirect


    Some user agents do some optimization on links and do not change the
    location while a link is active, but cache the assignments to location
    properties instead. You can watch this in MSIE, while Gecko based
    browsers would do what you expected. After executing your function,
    the link is executed and "javascript:;" is assigned to the href
    property, overwriting what was assigned by your function. Simply
    return false in your click event handler to suppress the link's
    default action:

    <a href="#" onclick="confirmNewSupplier(); return false" ...>...</a>

    A better approach that would keep the document working in User Agents
    not using JS (or having JS disabled) would be:

    function confirmNewSupplier(){
    return confirm(
    ' Are you sure that you can\'t select a supplier from the '
    + 'list? \n(Click OK to request a new supplier or Cancel to '
    + 'return to the Directory)'
    );
    }
    ....
    <a href="l1stage1.php" onclick="return confirmNewSupplier()" ...>...</a>

    I would prefer another variant that separates code and text:

    var oMsg = {
    ...,
    "NewSupCnf": "Are you sure that you can't select a supplier from the list?\n"
    + "(Click OK to request a new supplier or Cancel to return to the "
    + "Directory)",
    ...
    }
    ....
    <a href="l1stage1.php" onclick="return confirm(oMsg.NewSupCnf)" ...>...</a>

    ciao, dhgm
     
    Dietmar Meier, Mar 14, 2005
    #2
    1. Advertising

  3. thats great thank you


    "Dietmar Meier" <> wrote in
    message news:...
    > Craig Keightley wrote:
    >
    >> the link is as follows:
    >>
    >> <a href="javascript:;" onClick="confirmNewSupplier()"
    >> class="mainTextNormal">Creating a New Supplier</a>
    >>
    >> The alert pops up but it does not redirect

    >
    > Some user agents do some optimization on links and do not change the
    > location while a link is active, but cache the assignments to location
    > properties instead. You can watch this in MSIE, while Gecko based
    > browsers would do what you expected. After executing your function,
    > the link is executed and "javascript:;" is assigned to the href
    > property, overwriting what was assigned by your function. Simply
    > return false in your click event handler to suppress the link's
    > default action:
    >
    > <a href="#" onclick="confirmNewSupplier(); return false" ...>...</a>
    >
    > A better approach that would keep the document working in User Agents
    > not using JS (or having JS disabled) would be:
    >
    > function confirmNewSupplier(){
    > return confirm(
    > ' Are you sure that you can\'t select a supplier from the '
    > + 'list? \n(Click OK to request a new supplier or Cancel to '
    > + 'return to the Directory)'
    > );
    > }
    > ...
    > <a href="l1stage1.php" onclick="return confirmNewSupplier()" ...>...</a>
    >
    > I would prefer another variant that separates code and text:
    >
    > var oMsg = {
    > ...,
    > "NewSupCnf": "Are you sure that you can't select a supplier from the
    > list?\n"
    > + "(Click OK to request a new supplier or Cancel to return to
    > the "
    > + "Directory)",
    > ...
    > }
    > ...
    > <a href="l1stage1.php" onclick="return confirm(oMsg.NewSupCnf)"
    > ...>...</a>
    >
    > ciao, dhgm
     
    Craig Keightley, Mar 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernd Liebermann
    Replies:
    3
    Views:
    169
    Erwin Moller
    Feb 11, 2004
  2. Frances Del Rio

    window.location -- in a blank window....

    Frances Del Rio, Jul 22, 2004, in forum: Javascript
    Replies:
    12
    Views:
    813
    Grant Wagner
    Jul 26, 2004
  3. saiho.yuen
    Replies:
    3
    Views:
    556
    kaeli
    Sep 14, 2004
  4. Sunshine
    Replies:
    0
    Views:
    548
    Sunshine
    Sep 11, 2007
  5. Alex Bird
    Replies:
    3
    Views:
    212
    Thomas 'PointedEars' Lahn
    May 9, 2008
Loading...

Share This Page