View Full Version : Extracting a few characters from another page
gazboi1987
11-18-2009, 09:25 AM
hi guys. new to the forum but have been using dynamic drive for years :)
need some help with a script i'm looking for.
I need a script on my website that picks out the first couple of characters from another page.
it would be great if anyone can help me.
molendijk
11-18-2009, 12:27 PM
Main page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Including external content with ajax + object</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<!--[if !IE]><!-->
<script type="text/javascript">
document.write('<object type="text/html" name="object_name" width="0" height="0" data="external.html"><\/object>');
</script>
<!--<![endif]-->
<!--[if IE]>
<script type="text/javascript">
document.write('<iframe name="object_name" width="0" height="0" src="external.html"><\/iframe>');
</script>
<![endif]-->
<script type="text/javascript">
onload=function(){
document.getElementById('main_page_id').innerHTML = window.frames['object_name'].document.getElementById('some_external_div').innerHTML}
</script>
</head>
<body>
<div id="main_page_id"></div>
And this is the content of the main page.
</body>
</html>
External page (external.html):
<div id="some_external_div">
This is some part of of an external file<br>
</div>
This is the rest of the external file.
Arie Molendijk.
djr33
11-19-2009, 12:13 AM
That can work using Javascript, but another way (which doesn't depend on the browser having Javascript) is to use a serverside language.
With PHP, for example, you can do this fairly easily by using $p = file_get_contents('ADDRESS'); and $p = substr($p,0,2); (Where "2" is the number of characters you want).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.