Link to home
Start Free TrialLog in
Avatar of mohmedsh
mohmedsh

asked on

display contents from other urls within my pages

Hi
here is the senario. i have a client that needs to display other sites contents within his pages. following what i have tried and why it did not work.
1- using frames is bad idea and the client do not like it as the header and footer causing for sure scrolling in the contents and in a small area too. so that is not an option unless there is a way to display all the contents as one page without scrolling
2- i have tried iframes with auto resize. the problem that i can not find that it has been solved or maybe it can not be solved is cross-site scripting security that pervents geting the document hight in the iframe to resize it and results the permmision error. i have tried a dhtml script http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm but as mentioned it will get errors if used with urls out of the same domain.
3- grabing the text with php or asp results the page images and links to be broken. i have tried to add <BASE href='URL'> to correct the errors but that did not correct all relative links and images. also it did not work for javascript menu.
that is the situation and all what i have tried. I am open to any server side or client side that will enable me to dispaly the header+ contents from other url(actuly the whole page without any changes)+footer.
thanks for all your help
Avatar of pkaleda
pkaleda

You can use your ASP methode and programatically replace the href and image tags to include the referring domain in the code with replace.

Here is a sample:


<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Function GetHTML(strURL)
on error resume next
  Dim objXMLHTTP, strReturn
  Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

  objXMLHTTP.Open "GET", strURL, False
  objXMLHTTP.Send    
  strReturn = objXMLHTTP.responseText
  Set objXMLHTTP = Nothing

  GetHTML = strReturn
End Function
</SCRIPT>

<%
                  
'Define URL
myurl = "http://www.domain.com/directory1/index.html"
URLpath = "HTTP://www.domain.com/directory1/"

'Retreive URL
retval = GetHTML(myurl)

'Source Replacement
Source = replace(server.HTMLEncode(retval),chr(13),"<br>")
Source = replace(source, "href=", "href="&URLpath")

Response.write(source)
%>
You can try populateing a layer with XMLHTTP directly in the page.

You can use this script to bring external page into a layer in the page and let it size dynamically.  If necesary you should also be able to size and position the layer even after it is populated; but you still won't be able to script the target page.

<script language='JavaScript'>
<!--
function include(lyr,url)
{
   if (document.all)
   {
      // IE version
      try {
      var xml = new ActiveXObject("Microsoft.XMLHTTP");
      // some versions of IE4 and some IE5.0) might be using MSXML2.XMLHTTP.4.0
      xml.Open( "GET", url, false );
      xml.Send()
      document.getElementById(lyr).innerHTML=xml.responseText;
       }
      catch (e) {
      var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
      xml.Open( "GET", url, false );
      xml.Send()
      document.getElementById(lyr).innerHTML=xml.responseText;
      }
   }
   else
   {
      // Mozilla/Netscrap 6+ version
            var xml=new XMLHttpRequest();
            xml.open("GET",url,false);
            xml.send(null);
            document.getElementById(lyr).innerHTML=xml.responseText;
   }
}
//-->
</script>
You can trigger the script off the load:
<body onLoad="include('somediv','http://somepath/somefile.html'">
where somediv looks like: <div id="somediv">&nbsp;</div>

Or dynamically from a link:
<a href="#" onClick="include('somediv','http://somepath/somefile.html');return false">
   load alternate page
</a>

or inline as a conventional include:

<script language='JavaScript'>
   document.write('<div id="somediv">&nbsp;</div>');
   include('somediv','http://somepath/somefile.html');
</script>

If the string returned from the call contains valid HTML it will be rendered, otherwise it will display as plain text.

Does not work for older browser like Netscrap 4.x that do not know what XML is.

It can produce an alert if the user security settings have activeX disabled

Not the the url MUST be full qualified.

You have to actually test it across to a http server; it won't work just on the local file system.

Cd&
Avatar of mohmedsh

ASKER

pkaleda, you have added urlpath to my idea , it is good idea and through i can get the apsulate path of any images orlinks. But what about javascript links and menues, how would i deal with them?
COBOLdinosaur , I perfer using XMLHTTP on server side but here we are again what about links , images, javascript menues and javascript links in the url. how to provide working page without beoken items.
iframes was so good concept and i do not understand how it was working perfectly in my browser and resizing the page dynamically to any loaded page for 5 days without problems. Now it is not working in any browser but only mine :)
mohmedsh,

You are looking for an ideal solution that does not exist.  When you use external content that you do not control there are limitations.  There is also no guarantee that anything you get working will continue to work, because you cannot control, and may not even know about changes in the coding of the source pages.

If your client wants to grab pages from other sites then they need to know that the rendering is in the control of the source site.  You could pull down everything you need server side and generate the pages dynamically.  However if your client does not have permission from the sites to do that , then they may block your clients IP.

Of all the options iframe is the best, and if the client does not like the scrolling then tell them to make arrangements with the source sites to put code in the page to do the re-sizing of the window.  

Cd&
One other point to make.  You can spend 3 days coding to make it work and then when they revise their pages code a little, you have to recode all yours to make them work again.  

You also have to think of the legal issues with redisplay.  Do you have permission?  do they have a copyright?  
Here is the exact situation. I am not dealing with contents from other sites that is general like news, articales and so on. My client is an agent for those manufactures, They do not want to make a dbase to add the products from each manufactor as they may change , more added or more information available. They want to display all the information directly from the manufactures' sites , the data i will display will include the whole page with logos and other materals from the manufactures' sites. they already have permission to use the contents.
ASKER CERTIFIED SOLUTION
Avatar of pkaleda
pkaleda

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry COBOLdinosaur , i did not know how to choose assisted answer. can you please tell me how to correct this? may i do another Q for points or what.
Thanks all for your help
I will post points for Cobol.

pkaleda, I have no choice as you mentioned. I can not ask others to redesign their sites. I have only one option left that i tried to avoid, i have to use frame header.
Thanks
no pkaleda, just tell me how to post the points. I did not do it before.
I already posted them.  if you want me to cancel it, let me know.  now that this is answered you cannot split the points.  you would have to open a question called points for cobol like I did.
Thanks pkaleda, cancle your points and i will post one.
I added a comment in the points for Q that might give us an additional option, if any want to continue the quest for solutions. :^)

Cd&
actulay i am looking for soluation but it looks like there is no one. that is the limits we can work around as we do not have control over other sites' pages.
any way i will keep the other open till tomorow, maybe we get a trick while we are working :)