Results 1 to 14 of 14
  1. #1
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Arrow Display a file like Google with Javascript
    I know very little about Javascript I am a PHP programer so I struggle when I need to add in a Java routine.

    I figure it is very simple but I can not figure out how to display a files content with Javascript.

    In PHP I would do something like this:

    echo file_get_contents('http://www.google.com');

    and the file would display exactly as you would if you pointed your browser to google.


    I am looking for the Javascript equivalent. The google adsense uses this:

    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>

    I want to display an HTML file. These will be my one ad's / content feeds on my website.

    Thanks for any help and direction !!!
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  2. #2
    Affiliate Manager
    Join Date
    January 18th, 2005
    Posts
    1,056
    Hope I am understanding you right

    Here is what I do...

    1. Create your file that you want to display like such:
    (make sure it is all one on line, no line breaks)

    Code:
    document.writeln('This is the HTML code I want to show in the javascript');
    2. Save it to your server as something like "ads.html"

    3. Then call it on any site using:
    Code:
    <script language="javascript" src="http://www.yourdomain.com/ads.html"></script>

  3. #3
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    The evquivalent in Javascript would be

    window.location = 'http://www.google.com';

    That would have the effect as if the user typed it in the browser's address bar. If you wanted to open a second browser you would assign it to a variable and then call the open function on it. Hope this helps.

  4. #4
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    Also if you wanted to display on the same page like adsense you could use

    document.{element}.innerHtml = {html to show}


    Where {element} is a table or span in your html. This is how we do AJAX.

  5. #5
    Member
    Join Date
    April 11th, 2006
    Location
    Michigan
    Posts
    70
    Can you tell me any demo site with source code for Ajax site?
    Burhan Tanweer
    Marketing Manager
    sales/at/awebhosts.com
    [URL=http://www.awebhosts.com]www.awebhosts.com [/URL]

  6. #6
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Quote Originally Posted by DHolland
    Also if you wanted to display on the same page like adsense you could use

    document.{element}.innerHtml = {html to show}


    Where {element} is a table or span in your html. This is how we do AJAX.
    You are very close on your examples.

    What I would like to do is get the HTML a variable that I could display in java I want to grab the code with PHP or Java then pass it off to the display routine.

    Could you expand on this example here. and create a working example ?

    I would like to grab the contents of a file and replace your {html to show} with that information. So the Html would be on more than one line. The Html would look something like this:

    <p>bubbas Store<br>
    buy stuff.<br>
    <a href="http://www.bubba.com">www.bubba.com</a> </p>
    <p>&nbsp;</p>
    <p>Susies Store<br>
    buy stuff.<br>
    <a href="http://www.bubba.com">www.sue.com</a></p>
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  7. #7
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    Hi Apex, csearch

    I think I know what your trying to do but unfortunately I don't do much PHP work. I mostly do Java and .NET. But let me tell you how I would do this and maybe this might give you an idea in PHP. I use both the jsp:include and AJAX in a play site I have sudokucentral.net the puzzle uses AJAX to check the move and the deals on the right side are an example of the jsp:include and actually come from another site I have as well as Amazon web services. Here's some code I hope will help.

    If I wanted the HTML to be rendered at load time in Java (JSPs) I would use

    <jsp:include page="http:/www.domain.com/mypage.html" flush="true" />

    in the area where I want this to be displayed. Maybe in a <div>, <span>, or <table>

    If I wanted it to be displayed after loading as in response to a button click I would use AJAX and use document.{element}. innerHTML. I use JSON (java script object notation) instead on XML.

    You can use the javascript on load as well if you call it in the <body> element with onLoad="your proc".

    I would use the java version since it's easier and that's my specialty but here's most of what you need for the AJAX calls. The functions do the following

    newXMLHttpRequest() gets the XMLHttpRequest Object
    getReadyStateHandler handles the communication behind the scenes
    talkToJSONProc() does the communication with the servlet/jsp
    updateStuff() receives the html and inserts it into the page



    /*
    * Returns an new XMLHttpRequest object, or false if the browser
    * doesn't support it
    */
    function newXMLHttpRequest() {

    var xmlreq = false;

    // Create XMLHttpRequest object in non-Microsoft browsers
    if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();

    } else if (window.ActiveXObject) {

    try {
    // Try to create XMLHttpRequest in later versions
    // of Internet Explorer

    xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {

    // Failed to create required ActiveXObject

    try {
    // Try version supported by older versions
    // of Internet Explorer

    xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

    } catch (e2) {

    // Unable to create an XMLHttpRequest by any means
    xmlreq = false;
    }
    }
    }

    return xmlreq;
    }

    /*
    * Returns a function that waits for the specified XMLHttpRequest
    * to complete, then passes it XML response to the given handler function.
    * req - The XMLHttpRequest whose state is changing
    * responseXmlHandler - Function to pass the XML response to
    */
    function getReadyStateHandler(req, responseXmlHandler) {

    // Return an anonymous function that listens to the XMLHttpRequest instance
    return function () {

    // If the request's status is "complete"
    if (req.readyState == 4) {

    // Check that we received a successful response from the server
    if (req.status == 200) {

    // Pass the XML payload of the response to the handler function.
    responseXmlHandler(req.responseXML);

    } else {

    // An HTTP problem has occurred
    alert("HTTP error "+req.status+": "+req.statusText);
    }
    }
    }
    }

    function talkToJSONProc() {

    req = newXMLHttpRequest();
    req.onreadystatechange = getReadyStateHandler(req, updateStuff);

    req.open("GET", "testjson.jsp", true);
    req.send(null);
    }


    function updateStuff() {
    var jsonExpression = "(" + req.responseText + ")";
    var customer = eval(jsonExpression);

    // Find name of first item in customer's last order
    var name = customer.name;
    var datet = customer.date;

    var nameTable = document.getElementById("nameList");
    var tr = document.createElement("tr");
    var td = document.createElement("td");
    var oTextNode = document.createTextNode(customer.name);
    td.appendChild(oTextNode);
    tr.appendChild(td);
    nameTable.appendChild(tr);
    //alert("done updating table");

    var test = document.getElementById("deals");
    test.innerHTML = test.innerHTML + "<br/>" + customer.name;

    }

  8. #8
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    I have sent you a PM with the source code I am using in PHP. It may help explain it better, incase you do not get that here is the link: http://www.softebooks.com/ads/index.php
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  9. #9
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    Good morning apex, don't you sleep?

    Not sure exactly how Google does it but it can be accomplished with this code
    in javascript

    document.write("<iframe name=iframe1 src={yourhtml.html} width=120 height=600>");
    document.write("</iframe>");

    this will send the file yourhtml.html to this iframe window. It should be a html snippet and not full html with <html><body> tags. You can also do it on the fly with

    document.write("<iframe name=iframe1 width=120 height=600>");
    document.write("<div align="center">");
    document.write("<table border="0" cellpadding="2" style="border-collapse: collapse" width="120" id="table1">");
    .... the rest of your table code ...
    document.write("</iframe>");

    One note though, this is client side processing. Google only does it this way because it can't put the code on your server. Client side is slow. That's why the ads usually appear last or there's a blink in the browser. If possible I would do it through server side code with a include or rss feed. Much faster I think.

  10. #10
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    PS I couldn't get to the PM. I don't have the rights. Is there a threshold of posts or something?

  11. #11
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Quote Originally Posted by DHolland
    PS I couldn't get to the PM. I don't have the rights. Is there a threshold of posts or something?
    I think you are two away. I posted the same info in the forum. I will try you suggestions. Thanks for the help. After you hit the 50 mark I can send you my email if you ever need help with PHP.

    Apex

    I figure I can sleep along time when I die....
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  12. #12
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    It there a way to grab a page content and do somthing like this. Excuse my bad Java and I know this shouldn't work as written. But this would be a great for the purpose I need it for. I have been doing a lot of sufing but I have not found anything yet.

    <script>
    myvar = grab_some_file ("http://www.google.com");
    document.write( myvar );
    </script>
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  13. #13
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    You'll have to play with it but it is something like this

    Put this in your HTML where you want the ads to show

    <script type="text/javascript" src="http://your.server.com/show_ads.js">
    </script>


    Then in the file show_ads.js is where you would have the

    document.write("<iframe name=iframe1 src={your_ad_html.html} width=120 height=600>");
    document.write("</iframe>");

    or

    document.write("<iframe name=iframe1 width=120 height=600>");
    document.write("<div align="center">");
    document.write("<table border="0" cellpadding="2" style="border-collapse: collapse" width="120" id="table1">");
    .... the rest of your table code ...
    document.write("</iframe>");



    Make sense? If these are all your pages you can do it with just HTML too. Just use the iframe and pass your php file with parameters to determine what ads to display like

    <iframe name=iframe1 src={your_ad_html.php?ads=shoes} width=120 height=600>

    </iframe>

    This frame will show the content of http://{server}/your_ad_html.php?ads=shoes

  14. #14
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Quote Originally Posted by DHolland
    You'll have to play with it but it is something like this

    Put this in your HTML where you want the ads to show

    <script type="text/javascript" src="http://your.server.com/show_ads.js">
    </script>
    ............
    This frame will show the content of http://{server}/your_ad_html.php?ads=shoes
    That's what I was looking for, Awsome !! I will play with the code and tweak it for displaying my ad's.

    If you ever need some php tweaking look me up.

    Do you know of a good resource for the "document." directive ?


    Apex.
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  15. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Help! Display Image Based on Date/File Name
    By Matt McWilliams in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: November 13th, 2009, 09:43 AM
  2. Google new ad display builder
    By PatrickAllmond in forum Search Engine Optimization
    Replies: 3
    Last Post: October 16th, 2008, 06:46 PM
  3. Google Display URL POLICY CHANGE**
    By Paulson Management Group in forum Search Engine Optimization
    Replies: 10
    Last Post: August 31st, 2008, 11:49 AM
  4. How To Insert an External Javascript File into a Page?
    By jimh009 in forum Midnight Cafe'
    Replies: 3
    Last Post: May 22nd, 2004, 04:04 AM

Posting Permissions

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