2011-09-12 15:24
浏览 91

刷新父页面时请记住iFrame SRC

I have an intranet I am building, and am learning web languages as I go.

I have a basic html/php page that contains an iFrame, which most of my content is loaded into.

I also have a login box that is a popup modal within the main page. When you fill in this popup and hit login, it refreshes the main page, so that it knows you are logged in, and can display your name etc etc.

However, this means that the iframe SRC also resets to its default.

Is there a way to retain whatever the current SRC of the iframe is, when refreshing the parent page?

图片转代码服务由CSDN问答提供 功能建议

我正在构建一个内部网,我正在学习网络语言。 \ n

我有一个基本的html / php页面,其中包含一个iFrame,我的大部分内容都已加载到其中。

我还有一个登录框,它是一个弹出模式 主页。 当您填写此弹出窗口并点击登录时,它会刷新主页面,以便它知道您已登录,并可以显示您的姓名等。

但是, 这意味着iframe SRC也会重置为默认值。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dpleylxzx47207117 2011-09-12 15:27

    You can set a session variable to keep the current src.

    In your case I would do something like the following:

    All pages which are loaded in the iframe can contain the code to set the session var.

    session_start(); // before any output to the user-agent / browser /screen!!!
    $_SESSION['last_visited'] = $_SERVER['REQUEST_URI'];

    And on the page which displays the iframe you can simply do something like:

    session_start(); // before any output to the user-agent / browser /screen!!!
    echo '<iframe src="', $_SESSION['last_visited'], '"></iframe>';

    Regarding your question about saving the URL in the database.

    You could do that but I would just save it in a cookie.

    点赞 评论
  • douxitao8170 2011-09-12 15:37


    <form action="whatever" method="post">
        <input type="hidden" id="iframeSrc" name="iframeSrc"/>
        <input type="submit" onclick="addSrc()" value="Log in"/>
    <iframe id="mybox" src="somepage"></iframe>


    function addSrc() {
       document.getElementById('iframeSrc').value = document.getElementById('mybox').src;


    $iframeSrc = $_POST['iframeSrc'];
    echo "<iframe id=\"mybox\" src=\"$iframeSrc\"></iframe>";
    点赞 评论
  • dprnr5559 2011-09-12 15:41

    Why not just use Cookies

    function createCookie(name,value,days) {
        if (days) {
            var date = new Date();
            var expires = "; expires="+date.toGMTString();
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        return null;
    function eraseCookie(name) {
    点赞 评论

相关推荐 更多相似问题