传递URL变量

时间:2011-08-19 02:48:42

标签: php url variables

我有一系列共享相似结构但内容不同的页面,我称之为页面A(可能是其中任何一个)。我也有一个页面B,每个页面A链接到。所有页面A都是嵌入了iframe的WordPress帖子,而页面B是嵌入了iframe的WordPress页面,这取决于iframe URL来自引用页面A.Israme URL引用一组静态HTML页面(其中一个)因地理而异。)

我想将特定信息作为变量从每个页面A传递到页面B,这将定义页面B上的iframe和某些图像的URL。

第一个变量是页面A上iframe的URL。第二个变量是也在页面A上使用的地理代码,用于多个图像URL引用的中间(即http://mydomain.com/“geography_code “/img.jpg)。

我的问题:

  1. 如何将Page A iframe中使用的静态HTML网址定义为变量(请注意:不是引用的网页A网址,而是网页A上iframe中使用的网址)?定义地理位置没有问题。
  2. 如何将Page A iframe变量用作第B页上的iframe参考?
  3. 如何在第B页上的图片网址中间使用地理变量?
  4. 你能帮我解决这个问题吗?特别的PHP代码将不胜感激。我花了很多时间谷歌搜索和阅读相关的帖子,而没有排除这一点。在此先感谢您的帮助!

    干杯,

    布赖恩

1 个答案:

答案 0 :(得分: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

<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包含两个文件a.html和b.html

的来源

您可以使用b.html

中的以下行获取a.html的内容
var res1 = parent.one.document.body.innerHTML;

您可以通过以下行获取变量var1的值,该变量位于a.html中

var getvar1 = parent.one.var1; 

您可以使用以下行调用a.html中定义的函数fun1

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