在iFrame中显示用户以前的页面

时间:2015-12-11 04:14:10

标签: javascript html iframe

我正在尝试在iFrame中显示以前访问过的用户页面。

例如:如果有人访问了example.com,然后访问了mysite.com,那么我页面上的iframe将显示带有example.com的iframe。

我有以下代码:

的index.html

<body>
    <div>
        <h1>Welcome to mysite!</h1>
        <h3>Click the button to see a site you have previously visited</h3>
        <button id="button" onclick="magic()">Magic</button>
    </div>
    <br>
    <br>
    <div class="results"></div>

    <iframe id="myIFrame" height="80%" width="100%" class="netframe" src="http://www.cnn.com/"></iframe>
</body>

index.js

function magic (){

    $("#button").click(function(event){            
        $("#myIFrame").attr('src', window.history.back());
    });

}

现在,我正在尝试使用window.history.back()方法,但是当我尝试这样做时,什么都没有显示出来。当我单击按钮时,iframe不显示上一页。这有可能吗?

编辑: 我希望这样工作的方式是用户首先在example.com上,然后他们在mysite.com中输入TYPE才能访问我的网站。从example.com到mysite.com的导航不是通过example.com上的链接

2 个答案:

答案 0 :(得分:2)

使用# prepare the data: params = [ [ "param1", "value1" ], [ "param2", "value2" ], [ "param3", "value3" ] ] uri = ( "your_url_goes_here" ) # make your request: response = Net::HTTP.post_form( uri, params ) if( response.is_a?( Net::HTTPSuccess ) ) # your request was successful puts "The Response -> #{response.body}" else # your request failed puts "Didn't succeed :(" end 获取上一页网址,然后将其添加到iframe的src中。

document.referrer

我认为它会解决你的问题。

答案 1 :(得分:0)

您的JS功能正确但需要从

更改
`$("#myIFrame").attr('src', window.history.back());` 

改变

`$("#myIFrame").attr('src', window.history.back(0));`