2013-03-01 59 views
1

我有一個非常基本的框架佈局:index.html的元刷新與框架目標

<frameset rows="80,*" frameborder="1" border="5" framespacing="0"> 
    <frame name="topNav" src="top_nav.html"> 
    <frameset cols="220,*" frameborder="1" border="5" framespacing="0"> 
    <frame name="menu" src="menu_1.php" marginheight="0" marginwidth="0" scrolling="auto" noresize> 
    <frame name="content" src="content.php" marginheight="0" marginwidth="0" scrolling="auto" noresize> 
</frameset> 
</frameset> 

enter image description here

和檢查,如果用戶名和密碼匹配數據庫等簡單的登錄腳本

現在我希望它做的是,如果信息是正確的,是自動重定向的菜單欄,但所有我能做的就是重定向的內容部分

// check to see if they match! 
    if ($username==$dbusername&&$password==$dbpassoword) 
    { 
     $_SESSION['username']=$username; 
     echo '<meta http-equiv="REFRESH" content="2 ; url=servers.php" target="menu">'; 
    } 
    else 
     echo "<center>Incorrect Information!</center>" ; 

現在,我可以很容易地做到這一點,如果我讓用戶點擊一個<a href>標籤

E.G. <a href="servers.php" target="menu">click me</a>

所以我想我可以簡單地把target="menu"放在我的meta標籤中,但是它所做的只是重定向內容頁面。

所以我的問題是,我做錯了什麼,或者有一個更簡單的方法來做到這一點?

+1

它已經永遠自我見過一個網站上使用的框架...或元刷新此事。如果您已經在使用PHP,那麼爲什麼不將這些部分包含到您的顯示中 - 而不是創建框架......然後,您可以在成功登錄後執行標題('Location:something')。 如果你想堅持使用框架,我會使用JavaScript來強制重新加載元標記。 document.getElementById('menu')。location =「something」,也許? – Applehat 2013-03-01 20:49:00

+0

你好applehat,如果我是誠實的,我不是幀的大粉絲,但我想現在給它一段時間,所以我做了一個小項目,爲我自己,並已學會了許多事情辦法。但是,將來我會使用CSS,因爲它看起來更可靠。並感謝您的回答,它也工作:) – 2013-03-01 20:57:02

+2

沒問題!是啊。框架集和元刷新是網絡世界中真正的老技術。關於唯一的「可接受的」框架不再是iFrame ......甚至應該謹慎使用它們。 JavaScript讓你現在可以做得更乾淨=) – Applehat 2013-03-01 21:03:00

回答

3

我相信你不能使用標題。您可以在您的內容中輸出常規JavaScript。事情是這樣的:

<script> 
    parent.menu.location.href = "/some-url"; 
</script> 
+0

非常感謝,直接打開盒子,我一定會將你的答案標記爲已接受的答案 – 2013-03-01 20:53:38

2

給你架(菜單)的ID:然後改變這樣的代碼:

變化

echo '<meta http-equiv="REFRESH" content="2 ; url=servers.php" target="menu">'; 

echo '<script>var iframe = document.getElementById("youriframe");iframe.src="servers.php";</script>'; 
+0

謝謝你的回答,它工作得很完美。但是,當我們首先回答Nostrzak的答案時,我會將其標記爲已接受的答案,但仍然,非常感謝您花時間回答我的問題。 – 2013-03-01 20:58:55

+0

不客氣。而我thrac Nostrzak的答案也更簡單。 :d – MIIB 2013-03-01 21:00:15