Embed PHP code as Widget?

Discussion in 'PHP' started by Typr451, Mar 28, 2010.

  1. Typr451

    Typr451 New Member

    Joined:
    Apr 11, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I've got a little problem, I've got this application that produces a PHP-site and I'm trying to figure out how it can be embedded as a Widget on another site. My fingers are raw from Googling and my eyes hurt from from reading pointless articles related to Widgets that say nothing about how to load a normal HTML and PHP site as a Widget. The closest thing I got was someone writing HTML-code in a string and printing it in JavaScript, I wanted to do the same but I can't find a function to load the content of a URL into a string, plus from lurking i forums a lot say that's impossible.

    It've gone so far that I think I've completely misunderstood what a Widget is, isn't it just an external site, anywhere, which you load in another site? Why isn't anyone using iframes? I tried those but my host wouldn't allow it, so I've been checking some Widget-embedd examples and they use JavaScript for some reason.

    Anyway, I won't bore you with details, it should be so simple. If it wasn't clear: I've got a couple of pages, JavaScript, XML and PHP that fill up a DIV with some application. I want to be able to load that application as a Widget somewhere. Thanks :)
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes best part is JavaScript and I have done it for my blog as well.

    http://www.codeitwell.com/recent-posts.js

    See this and you can embed this js file on any of your site and it will start showing the recent posts from my blog.

    You have the have the ability in your PHP server to create a file which can make such an output and then its just plain adding in any page is fine.
     
  3. Typr451

    Typr451 New Member

    Joined:
    Apr 11, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I'm not sure I understand. What I got looks a lot like the AJAX-example on W3Schools with a XML-file as the database, a JavaScript-file that prints the information from a PHP-file and just the plain HTML-file that loads the JavaScript.

    What I first tried was using an iframe on my blogg that linked to the PHP-page (which has all the data I want) but it wouldn't allow it, just like my host. Then, since I could print HTML directly with JavaScript on the blogg, I tried printing some PHP-code but it didn't work. After that I tried loading the XML-file directly in JavaScript (too the file on my server with full URL) but that didn't work as well.

    What I think I need is somehow load the content of a URL (my PHP-page) into JavaScript as plain HTML and just write it.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    if iframe does not work I think you can change your host.

    If you are looking for inclusion of a phpfile you can make a second file on the server which converts your html into a javascript
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice