How to make an HTML back link?

后端 未结 12 803
臣服心动
臣服心动 2020-12-12 08:32
相关标签:
12条回答
  • 2020-12-12 09:01

    The easiest way is to use history.go(-1);

    Try this:

    <a href="#" onclick="history.go(-1)">Go Back</a>

    0 讨论(0)
  • 2020-12-12 09:03

    history.go(-1) doesn't work if you click around in the 2nd domain or if the referrer is empty.

    So we have to store the historyCount on arriving to this domain and go back the number of navigations in this side minus 1.

    
    // if referrer is different from this site
    if (!document.referrer.includes(window.location.host)) {
      // store current history length
      localStorage.setItem('historyLength', `${history.length}`);
    }
    
    // Return to stored referrer on logo click
    document.querySelector('header .logo').addEventListener('click', 
      () =>
       history.go(Number(localStorage.getItem('historyLength')) - history.length -1)
    );
    
    0 讨论(0)
  • 2020-12-12 09:06

    you can try javascript

    <A HREF="javascript:history.go(-1)">
    

    refer JavaScript Back Button

    EDIT

    to display url of refer http://www.javascriptkit.com/javatutors/crossmenu2.shtml

    and send the element a itself in onmouseover as follow

    function showtext(thetext) {
      if (!document.getElementById)
        return
      textcontainerobj = document.getElementById("tabledescription")
      browserdetect = textcontainerobj.filters ? "ie" : typeof textcontainerobj.style.MozOpacity == "string" ? "mozilla" : ""
      instantset(baseopacity)
      document.getElementById("tabledescription").innerHTML = thetext.href
      highlighting = setInterval("gradualfade(textcontainerobj)", 50)
    }
     <a href="http://www.javascriptkit.com" onMouseover="showtext(this)" onMouseout="hidetext()">JavaScript Kit</a>

    check jsfiddle

    0 讨论(0)
  • 2020-12-12 09:07
    <a href="#" onclick="history.back();">Back</a>
    
    0 讨论(0)
  • 2020-12-12 09:08

    For going back to previous page using Anchor Tag <a>, below are 2 working methods and out of them 1st one is faster and have one great advantage in going back to previous page.

    I have tried both methods.

    1)

    <a href="#" onclick="location.href = document.referrer; return false;">Go Back</a>
    

    Above method (1) works great if you have clicked on a link and opened link in a New Tab in current browser window.

    2)

    <a href="javascript:history.back()">Go Back</a>
    

    Above method (2) only works ok if you have clicked on a link and opened link in a Current Tab in current browser window.

    It will not work if you have open link in New Tab. Here history.back() will not work if link is opened in New Tab of web browser.

    0 讨论(0)
  • 2020-12-12 09:09

    try this

    <a href="javascript:history.go(-1)"> Go Back </a>
    
    0 讨论(0)
提交回复
热议问题