Hi, I am new here and am am not a "professional" developer of any sort. Except for some introductory computer science courses at my university, I am mostly self taught so please excuse my ignorance and inexperience.
Background:
I remember once learning some PHP, but whatever I learned I forgot and so I am here today to ask a simple question. Also, I know HTML, CSS, and Javascript and I've just started looking into AJAX (seems pretty simple so far). I know Python, Java, and C++.
Question:
I want to do something that I know is pretty clunky and unprofessional, but is the easiest to implement solution (I can find) that does what I need. I want to create an iframe that loads cross domain content and while doing so, adjusts its size to the page it loads. I have decided to use a PHP proxy which seems simple enough. I believe my server settings for PHP will not give me problems with this. I have a simple proxy does the basic thing of getting the cross domain page content, but I dont know how get simple information from the content such as height width of the body. Now I understand that I could just stuff the content into a div, but since I want the frame to axcess any page on the web, the proxy will be an open proxy which can then be taken advantage of by user with possibly ill intentions. So, I am limiting the php script to only getting height and width informations. Again, how do I get this information?
This is the example I am basing my proxy from.
<?php
// Set your return content type
header(Content-type: application/xml);
// Website url to open
$daurl = http://feeds.feedburner.com/jQueryHowto;
// Get that website is content
$handle = fopen($daurl, "r");
// If there is something, read and return
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
Excuse my round about way of explaining myself.
How to: get dimensions of page opened by php script?
Moderator: General Moderators
Re: How to: get dimensions of page opened by php script?
Here is what I ended up doing which works (with some minor glitches that I hopefully can fix)
I made a simple proxy: myproxy,php
Then I resized the iframe based on the height and width of the page retrieved through the proxy. I did this when the page loaded and when it is resized.
Javascript code:
I made a simple proxy: myproxy,php
Code: Select all
html>
<?php
$daurl = $_GET['url'];
//This next part is necessary; it allows people axcess
// to the links in the content of the retrieved page
echo '<head><base href='.$daurl.'></head><Body>';
// Set your return content type
//header(Content-type: application/xml);
// Website url to open
// Get that website is content
$handle = fopen($daurl, "r");
// If there is something, read and return
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
</body>
</html>Javascript code:
Code: Select all
fr = 0;
proxyAddress = "http://meadowlark.unl.edu/~abouzid/underconstruction/proxyTest.php";
frameWidthOffset = -46;
function goTo(url){
fr = document.getElementById("fr");
fr.src = proxyAddress + "?url=" + url;
resizeFrame();
}
function resizeFrame() {
fr = document.getElementById("fr");
if(fr.contentWindow.document.body.scrollHeight > document.body.clientHeight){
fr.style.height = fr.contentWindow.document.body.scrollHeight +'px';
}
else{
fr.style.height = document.body.clientHeight + 'px';
}
if(document.body.clientWidth > fr.contentWindow.document.body.scrollWidth){
fr.style.width = document.body.clientWidth + frameWidthOffset + 'px';
}
else{
fr.style.width = fr.contentWindow.document.body.scrollWidth + 'px';
}
}