Alternative to iFrame to pull in actual data from

2019-08-02 22:28发布

OK... I'll try to be complete with my question (so, sorry for the lengthiness)... I've been trying to search all over the web for an ideal solution. I build our company's web site (self taught) and things are starting to come together with some nice css and php includes for my header and footer, and getting ready to use some Media Queries in my CSS with different browser sizes/resolutions and get some nice responsive web design going. As a product supplier in our industry, we upload product data into a service called Sage. They provide us with a personal website we CAN use that pulls in our product data that we give them. However, their site design isn't great and we'd like to just pull in the product data into our own existing site.

Currently our site pages for each product category just uses an iframe with the src URL pointing to the link generated by the results of the search form on the Sage site they provide us. Obviously this isn't great since it's slow to pull the data in, and my iframe has to be sized to always fit the max height since i don't want scroll bars for the iframe.

Again, I am self taught with web development with my only tools being a healthy amount of google... and just reading source code, so if you have any recommendations, please be specific and detailed.

I have found something on this site posted by someone else that actually ALMOST works for me using the following code (I am testing at this URL (if you want to see whats happening).

It's using the following code:

<?php $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.promoplace.com/ws/ws.dll/StartSrchDistID=36182&ProdSelect=&Srching=1&CatName=Pens&catmoveto=Pens&category=221&keywords=&itemnum=&LoP=&HiP=&Qty=&Search.x=44&Search.y=22&Search=submit&GlobalSearch=");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); ?>
<?php $result = curl_exec($ch);
curl_close($ch); ?>
<?php $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+([\"'>]+)#",'$1http://www.promoplace.com/$2$3', $result);
echo $result ?>

If you look at my test page... the data is coming over well enough, but the external images don't display, and when you click through to view "more details" it appends the correct actual link data that should come after the external domain to MY domain, which points to a directory that exists externally, and not on my domain. It's obviously because the images are using links written for the directory locally. I am assuming that the $results = preg_replace..... ... command above is to in some way correct this, so maybe I am doing it wrong and I'm almost there already.

If anyone has any ideas, or a better, cleaner way to accomplish this, your help would be really greatly appreciated. I am really learning a lot, and enjoying it all.

标签: php html iframe
2条回答
Anthone
2楼-- · 2019-08-02 22:42

If you don't want to use iframe and you are using jQuery, you can do something like this. Try the following code:

Instead of an iframe tag use div tag

<div id="divId"></div>

Place this code inside your <head> tag

<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.4'></script>

<script type='text/javascript'>
$(document).ready(function (){
$('#divId').load(url of target website what you must load);     
});
</script>
</head>

All the contents from target site or page(specified url) will be inserted inside the #divID div tag. Hope this helps. All the best!

查看更多
The star\"
3楼-- · 2019-08-02 22:58

You can try the object element which will allow you to click on links that target the child page. Try this:

<object height="100%" width="100%" data="http://foo.com">

set your style to:

html, body{height: 100%;min-height: 100%;}

Make sure you set up CORS if the child page is NOT on the same domain as the parent page.

查看更多
登录 后发表回答