Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: stuck in page...any help?

  1. #1
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default stuck in page...any help?

    Hey to all!
    I really need your help here, could not find any solution.

    I have a product index
    -> user selects item
    -> detail page xxx.htm loads and a script is loading Variants & Category ID's for this url). The loaded htm looks now like xxx.htm?categoryId=45
    What actually happens is, that page is loading twice to browser's history

    ->now, user views the product detail page, he can put the item to shopping cart..and will be redirected to the orderform.htm.
    -> Or...user wants to navigate back....but he stucks at the current page!!

    I have added a back button with history.go(-2), works fine....
    but how can I fix the bug if the user (and he will) uses the browser back button?

    You may see it at:
    http://www.12voltshop.gr/pi-1517753331.htm
    (see how categories are loaded when entering the page)

    I need a command that executes onunload:

    Only
    if (the user uses browser back button)
    history.go(-2)
    else (if, he chooses to put the item to shopping cart ->exetute the script for that action

    or

    The other solution would be not to run the script wchich loads variants & ID's when navigating one(1) history back.

    Help is appreciated.

    Dimi
    Last edited by pivey; 09-10-2005 at 02:27 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Use location.href.replace(url). This will prevent the first page from being added to the history.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Twey..thank you.
    I have done this. It does not work. Strange...don't know how to explain but in fact it is the same page....so if I use this command the page tries to reload...reload...reload

    Know what I mean?

    I need a function which "sees" that the browser goes 1 back...so the history should be (-2) in that case.
    Else...if the user selcts the item to place it to the shopping cart->execute addToBag()

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It can and perhaps should be:

    location.replace('url')

    But, more importantly is how did you use this? If used in a script that runs each time the page is loaded, a test must be made to be to see if the query string has already been added or not. Since you have a lot going on in both pages, show us the exact script where the query string is added, highlighting the code that does it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello John!
    The script is executed every time a page is loaded:
    var urlstring="defaultVariants=";
    var baseurl=location.href.split("?");
    var jx=location.href.search(/&/);
    if (proComb[0][5]!="" && jx==-1){
    for (var i=5;i<proComb[0].length;i++){
    urlstring+='search'+(i-5)+'_EQ_'+proComb[0][i]+'_AND_';
    }
    urlstring+='%7BEOL%7D';
    location.href=baseurl[0]+'?'+urlstring+'&categoryId='+(Product.EANCode);
    }
    else if(location.href.search(/=/)==-1) location.href=baseurl[0]+'?categoryId='+Product.EANCode;


    Well, I found a way(i you can say so) that now does return to the product index using
    <script>
    var mypageback = "pi644791070.htm"
    var i=true;
    </script>

    <body onunload='if(i) window.location=mypageback'>


    Everything works fine, back with browser, AddToBag, Refresh....but the problem now is that if you click any other link (like product recommendation, help desk etc.) , even then the page returns to the same pi644791070.htm

    I have placed a product for your inspection at
    http://www.12voltshop.gr/pi644791070.htm the first item "Alphasonik PSW 612"

    Dimi

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's brilliant! Now all you need to do is, in the links that you do not want to go to pi644791070.htm, put this:

    Code:
    onclick="i=0;return true;"
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John , you are right!
    Solving this would be onClick="i=false;" as well

    But since the other links are genaretad autom. it is a lot of work to do afterwards for all pages to add onClick....

    How can I have a script (maybe based on the one who does load variants...)which does:
    ONLY if the user goes back to previous page ->run onunload='if(i) window.location=mypageback'
    ELSE: follow other links as they are

    Thanks
    Dimi

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    onclick="i=false;" would not work. The = operator, as well as assigning the value to the right, also returns that value. This would be the same as "i=false;return false;" The link will not work.

    I'm not sure if you can do what you requested above. Something with cookies, perhaps?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    First of all, I'm not sure what Twey is saying but, in any case, adding:

    onclick="i=0;return true;"

    or:

    onclick="i=false;return true;"

    to a link will still allow the link to fire when clicked. That out of the way, we could add to the onload event(s) that fire for the page, language that adds this onclick event only to the links we desire. Something like this:
    Code:
    <script type="text/javascript">
    function addTrue(){
    var links=document.getElementsByTagName('a')
    for (var i_tem = 0; i_tem < links.length; i_tem++)
    if (links[i_tem].href.indexOf('pi644791070.htm')==-1&&links[i_tem].href.indexOf('javascript')==-1)
    links[i_tem].onclick=function(){i=0;return true;}
    }
    </script>
    Still, if possible, it would be better to catch the query string addition and reload and prevent it from happening a second time. This was my first idea, something like:
    Code:
    if (location.href.indexOf('?')!==-1)
    return;
    added to your function that adds the query string and reloads the page in the first place. Then, also employing the location.replace() method should not cause the multiple reloads. I'm having trouble following your code for that and perhaps '?' would not be the best character to test for but, there should be something we could use.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello! John you are right.
    I used this one:
    <script>
    function setLinks(){
    var lnk = document.links;
    for(var n=0;n<lnk.length;n++){
    lnk[n].onclick = function(){i=false};
    }
    }
    </script>

    <body onload="setLinks()" onunload='if(i) window.location=mypageback'>

    Well, it works...except some deep links (like bundled item links) but I don't worry about that 'cause I want to change them to _blank windows anyway.

    Your script sounds good, the prob is that I will have to do this for 1600-2000 pages.
    However to catch the query string addition has to be the most advanced solution for that.
    But that means that the script must recognize the final URL to be built uppon load.....hmmm I can't figure it out.
    But it works now!
    If you have an idea I would be glad to hear it.

    Dimi

Bookmarks

Posting Permissions

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