Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 浏览器后退按钮不可用';将内容加载到iframe中时无法工作_Javascript_Html_Iframe_Browser_Back Button - Fatal编程技术网

Javascript 浏览器后退按钮不可用';将内容加载到iframe中时无法工作

Javascript 浏览器后退按钮不可用';将内容加载到iframe中时无法工作,javascript,html,iframe,browser,back-button,Javascript,Html,Iframe,Browser,Back Button,我有一个javascript函数,当用户单击链接时,我使用该函数显示一些内容 function showContent(filename){ var oldcontent = $('#content').html(); var srcUrl = getSourceUrl(filename); $('#content').html(oldcontent + '<iframe style="width:100%;height=100%;display:block;" src="'+

我有一个javascript函数,当用户单击链接时,我使用该函数显示一些内容

function showContent(filename){
  var oldcontent = $('#content').html();
  var srcUrl = getSourceUrl(filename);
  $('#content').html(oldcontent + '<iframe style="width:100%;height=100%;display:block;" src="'+srcUrl+'" />');
}
函数showContent(文件名){
var oldcontent=$('#content').html();
var srcUrl=getSourceUrl(文件名);
$('#content').html(oldcontent+'');
}
由于内容已加载到IFrame中,因此URL不会更改,并且我无法返回到上一页,该页中的链接使用了浏览器的“后退”按钮。我是一个新手,我试着做这样的事情(愚蠢的实验)。i、 e.在url中添加一个“#page2”,但当用户单击后退按钮时,什么也没有发生

var oldcontent = $('#content').html();
var srcUrl = getSourceUrl(filename);
location.href = location.href + '#page2';
$('#content').html(oldcontent + '<iframe style="width:100%;height=100%;display:block;" src="'+srcUrl+'" />');
var oldcontent=$('#content').html();
var srcUrl=getSourceUrl(文件名);
location.href=location.href+“#第2页”;
$('#content').html(oldcontent+'');
有谁能告诉我这有什么问题,以及如何启用“后退”按钮功能吗?

试试这个:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Hash Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  </head>
  <body>
    <div id='message-container'></div>
  </body>
  <script>
    var messages = ["Hello. Click anywhere on the page.", "How are you?", "I hope you're fine.", "Have a nice day and hit the back button."];
    var currentMessage = 0;
    var lastMessage = messages.length - 1;

    $(document).click(function() {
      nextMessage();
    });

    function nextMessage() {
      if (currentMessage < lastMessage) {
        currentMessage++;
        updateHash();
      }
    }

    function displayMessage() {
      $("#message-container").text(messages[currentMessage]);
    }

    function updateHash() {
      window.location.hash = "#message" + currentMessage;
    }

    $(window).on("hashchange", function() {
      if (/message\d+/.test(window.location.hash)) {
        currentMessage = window.location.hash.match(/message(\d+)/)[1];
        displayMessage();
      }
    });

    updateHash();
  </script>
</html>

散列测试
var messages=[“你好,点击页面上的任何地方。”、“你好吗?”、“我希望你很好。”、“祝你有愉快的一天并点击后退按钮。”;
var currentMessage=0;
var lastMessage=messages.length-1;
$(文档)。单击(函数(){
nextMessage();
});
函数nextMessage(){
如果(currentMessage
在旧浏览器中查看
hashchange
事件,在新浏览器中查看
history.pushstate