2011-08-19 97 views
1

我有一系列頁面共享一個類似的結構,但有不同的內容,我會打電話給頁面A(可能是其中的任何一個)。我也有一個頁面B,每頁A鏈接到。所有頁面A都是嵌入了iframe的WordPress帖子,頁面B是嵌入了iframe的WordPress頁面,這取決於引用頁面A的iframe URL。iframe URL引用了一組靜態HTML頁面(其中因地理而異)。通過URL變量

我想將特定信息作爲變量從每個頁面A傳遞給頁面B,頁面B將定義頁面B上的iframe和特定圖像的URL。

第一個變量是頁面A上的iframe的URL。第二個變量是也在頁面A上使用的地理代碼,用於幾個圖像URL引用的中間(即http://mydomain.com/「geography_code」/ img .JPG)。

我的問題:

  1. 如何定義頁面中使用靜態的HTML URL一個IFRAME作爲變量(注意:不是指頁面的URL,但在第一個iframe中使用的URL)在頁面B的鏈接?確定地理位置不成問題。
  2. 如何將Page A iframe變量用作頁面B上的iframe引用?
  3. 如何在頁面B上的圖片網址中間使用地理變量?

你能幫我解決嗎?具體的PHP代碼將不勝感激。我花了相當多的時間搜索相關文章,但沒有對此進行整理。在此先感謝您的幫助!

乾杯,

布賴恩

回答

0

我不能清楚地瞭解你的問題。所以我提供了一個通用的解決方案來訪問另一個文件中的iframe內容。希望這對你有幫助。

main.html中

<html> 
<head><title>Parent Page</title></head> 
<body> 
<h3>Parent Page</h3> 
<iframe src="a.html" id="one" name="one"></iframe> 

<iframe src="b.html" id="two" name="two"></iframe> 
</body> 
</html> 

child1.html

<html> 
<head> 
<title>Child 1</title> 
<script type="text/javascript"> 

var var1 = 'Test'; 

function fun1(txt) { 
    document.getElementById('div1').innerHTML = txt; 
} 
</script> 
</head> 
<body> 
IFRAME 1 Content in BODY 
<div id="div1">Div content of the iframe 1</div> 
</body> 
</html> 

child2.html其中包含兩個文件來源a.html

<html> 
<head></head> 
<title>Child 2</title> 
<body>IFRAME 2<br> 

<script type="text/javascript"> 
function function_in_child2(txt) { 
    var res1 = parent.one.document.body.innerHTML; //this gets the content of the IFRAME1 named as "one" in main.html 

    alert(res1);   

var getvar1 = parent.one.var1; // gets the value of the variable "var1", which is defined in the child1 (iframe1 named as "one" in parent form) 
document.getElementById('div2').innerHTML = getvar1; //displays the variable var1 in div2 

parent.one.fun1("This value goes to fun1 of child1"); // Calls the function "fun1", defined in child1 
} 
</script> 
<div id="div2"></div> 
<button onclick="function_in_child2('<b>The text changed from iframe 2</b>')">Click Me</button> 
</body> 
</html> 

有第一個文件main.html中和b.html

您可以使用b.html下面的線

var res1 = parent.one.document.body.innerHTML; 

你可以得到變量VAR1的值,它是在a.html通過下面的線

var getvar1 = parent.one.var1; 

得到a.html的內容您可以使用以下行調用在a.html中定義的函數fun1

parent.one.fun1("This value goes to fun1 of child1");