我按照@ SequenceDigitale.com回答here设置了外部iframe here的样式。一切都很好,但是当我对表格数据进行排序或在iframe中搜索时,页面会重新加载但旧的设计出现了。这是为什么?
的代码
我正在使用此代码从外部资源中获取数据
<?php
$content = file_get_contents('http://www.exhibition-directory.com/expostars/index.php/');
$content = str_replace('</title>','</title><base href="http://www.exhibition-directory.com/expostars/" />', $content);
$content = str_replace('</body>','<link rel="stylesheet" href="http://www.informatixtech.com/expostars/wp-content/themes/hotstar-child/hotstar-child/custom.css" type="text/stylesheet" /></body>', $content);
$content = str_replace('</head>','<link rel="stylesheet" href="http://www.informatixtech.com/expostars/wp-content/themes/hotstar-child/hotstar-child/custom.css" type="text/stylesheet" /></head>', $content);
echo $content;
?>
这是我的iframe代码
<?php
echo '<iframe id="iframe" src="http://www.informatixtech.com/expostars/search-page.php" name="Stack" height="1200" frameborder="0" scrolling="auto" width="100%"></iframe>';?>
答案 0 :(得分:1)
表单使用$ _GET变量,因此您可能会执行类似
的操作$content = file_get_contents('http://www.exhibition-directory.com/expostars/index.php?'.http_build_query($_GET));
以便传递给表单的所有变量都附加到获取的URL
添加此项,以便表单提交到您的服务器:
$content = str_replace('<form name="searchForm" action="index.php" enctype="multipart/form-data" method="get">','<form name="searchForm" action="http://www.informatixtech.com/expostars/search-page.php" enctype="multipart/form-data" method="get">', $content);
更新您的CSS,使其不依赖于表单[action = index.php]
<强>更新强>: 添加此项以便重写链接:
$content = str_replace("location.href='index.php?","location.href='http://www.informatixtech.com/expostars/search-page.php?", $content);
再替换一次:
str_replace('<div class="sc-button-reset"><a href="index.php','<div class="sc-button-reset"><a href="http://www.informatixtech.com/expostars/search-page.php', $content);
答案 1 :(得分:0)
在您抓取并在iframe中返回的页面中,将点击处理程序添加到需要重新加载的所有链接中。
使用jQuery
$(function(){
$('a').click(function(){
var otherSiteHref = encodeURIComponent(this.href);
var yoursSiteProxyUrl ='/path/to-your-php?url=' + otherSiteHref ;
this.href = yoursSiteProxyUrl ;
});
});
然后在服务器解码$_GET['url]
,从远程站点获取新的html并发送它。
对于表单,在php中设置一个控制器方法,并将操作更改为指向您的代理
$('#searchForm').attr('action', '/your-search-proxy.php');
您需要向搜索表单的其他网站发出cURL请求。