开发者

How to load an external website in a div with out iframe [closed]

开发者 https://www.devze.com 2023-01-17 22:16 出处:网络
开发者_高级运维 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_高级运维 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How to load an external website in a div? I must not use an iframe.


You can try using Uframe

http://www.codeproject.com/KB/aspnet/uframe.aspx


You could use an object, which will be treated a bit like an iframe, but with less consistent browser support (making it a very poor alternative to an iframe). I've only seen this used in exercises to use HTML Strict when Transitional (or a redesign to avoid the feature) is called for.

You could parse the data from the remote server on your server and bundle it in up in the original page.


Interesting... Conceivably, you could write the content of a webpage gotten via a curl request to the innerhtml of a div... I'm postulating, of course; I have no desire to try this out, but here's some code if you'd like to give it a whirl...

Some server-side php... let's call it pageloader.php

<?php
// Check for cURL
if( !function_exists( 'curl_init' ) ) die( 'cURL is not installed.' );

// Create a cURL resource handler (cURL Handler = ch)
$ch = curl_init();

// Set options
curl_setopt( $ch, CURLOPT_URL,            "http://www.example.com/"   );    // URL from which to download
curl_setopt( $ch, CURLOPT_HEADER,         0                           );    // Include header? (0 = yes, 1 = no)
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true                        );    // Return or Print? (true = return, false = print)
curl_setopt( $ch, CURLOPT_TIMEOUT,        10                          );    // Set a maximum time before timeout (defined above)

$output = curl_exec( $ch );

curl_close( $ch );

echo $output; ?>

Then a little javascript... I'll just assume you're going to do a specific page on page load...

window.onload = function() {
  var req = encodeURIComponent( document.getElementById('ajax_location').value );
  if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange = function() {
    if( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) document.getElementById("output").innerHTML = xmlhttp.responseText;
  }
  xmlhttp.open( "GET", "pageloader.php", false );
  xmlhttp.send( );
}

And finally your index.html, where presumably you'd be displaying another's hard work as your own inside a massive div:

<body>
  <div id="output" style="width:960px;height:480px;overflow:scroll"></div>
</body>

Of course, this might just end up as a bunch of unrendered html, but it was a fun bit of mental calisthenics anyhow.


You can use iframe in Div for to call external web site in it.

0

精彩评论

暂无评论...
验证码 换一张
取 消