Prevent Extra History Item

Discussion in 'HTML & Website Design' started by zenoxman, Aug 7, 2008.

  1. #1
    I'm making a search engine that has to crawl clicked results for their links. The problem is that when a result is clicked, the user has to press the back button twice to return to the search engine instead of once. This is the code just for the test crawler (crwltstS.htm):

    <html><head>
    <base id="bas" href="crwltstS.htm" />
    <script type="text/javascript">
    function cal()
    {
    alert(cwl(document.getElementById('url').value));
    }
    function cwl(whr)
    {
    xbj = new XMLHttpRequest();
    xbj.open("post",whr,false);
    xbj.send(null);
    parent.document.frames[0].document.write(xbj.responseText); //probably the problem
    document.getElementById("rps").innerHTML = blk.document.getElementsByTagName("body")[0].innerHTML.replace(/<a /gi,"<a id='0' ");
    parent.document.frames[0].window.location.replace("crwltstB.htm");
    document.getElementById("bas").href = whr;
    anx = document.anchors;
    len = anx.length;
    lnx = new Array();
    for(pos = 0; pos != len; pos++)
    {
    lnx[pos] = anx[pos].href;
    }
    document.getElementById("rps").innerHTML = "";
    document.getElementById("bas").href = "crwltstS.htm";
    return lnx;
    }
    </script></head><body>
    <input type="text" size="100" id="url" />
    <a href=erl.value onclick="cal();">
    Crawl & Visit This Site!
    </a>
    <div id="rps">
    </div></body></html>

    Clicking on the link sends the user to the location typed in a textfield after alerting all links in that location. The links are extracted by

    1. Getting the source via XMLHttpRequest and writing it into a neighboring empty frame (crwltstB.htm)
    2. Copying the written <BODY> content into a <DIV> element while giving every link an id so DOCUMENT.ANCHORS sees them all
    3. Clearing the sibling frame for further use while changing the <BASE> HREF so the links work right
    4. Saving the link HREFs to an array before resetting the <BASE> HREF and <DIV> content for further use.

    Why is there an extra history item, and how can I prevent it? WINDOW.LOCATION.REPLACE() isn't the problem; I checked.
     
    zenoxman, Aug 7, 2008 IP
  2. zenoxman

    zenoxman Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A more specific question is, what can I do instead of

    parent.document.frames[0].document.write(xbj.responseText);

    to be able to extract the <BODY> content of an XMLHttpRequest? Or how would I use

    history.back();

    whenever the user presses the back button to return to the search engine?
     
    zenoxman, Aug 9, 2008 IP