Advanced Search

Results 1 to 3 of 3

Thread: Extracting a few characters from another page

  1. #1
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Extracting a few characters from another page

    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.

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,297
    Thanks
    28
    Thanked 135 Times in 130 Posts
    Blog Entries
    28

    Default

    Main page:
    Code:
    <!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):
    Code:
    <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.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    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).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •