SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Javascript loader (MAC)

    Is there a way of getting javascript to load or reload on a mac?

    At the moment I use this function
    Code:
    function addScript(js) {
    mybody=document.getElementsByTagName("body")[0];
    newScript = document.createElement("SCRIPT");
    mybody.appendChild(newScript);
    newScript.setAttribute("type","text/javascript");
    newScript.setAttribute("src",js);
    }
    but it doesn't seem to work on the mac.

    I know I have the option of working with xml, but why would I want to create another output when my script already has a html output.

    I use it like this (php)
    Code:
    $html="";
    $html.="<h1>livescript</h1><p><a href=\http://www.sitepoint.com\ title=\"sitepoint\">Sitepoint</a>";
     
    if($_GET["live"]=="on"){
    header("ContentType: application/x-javascript");
    echo "document.getElementsByTagName(\"body\")[0].innerHTML=\"".preg_replace("/\"/","'",$html)."\"";
    } else echo $html;
    works nicely, but not on a mac.

    Any suggestions?

    I have it working (on pc) at www.publiknotice.com, where if you click on a pic the preview comes in the footer. This is then repeated every few seconds so changes are shown live.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't work on "mac"? Not so helpful. There are 99 browsers available for Mac...

  3. #3
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this, it works in Safari 2.

    For literal javascript:
    Code:
    function addScript(js) {
        myHead = document.getElementsByTagName('head').item(0);
    
        newScript = document.createElement('script');
        newScript.setAttribute('type', 'text/javascript');
        newScript.appendChild(document.createTextNode(js));
    
        myHead.appendChild(newScript);
    }

    For external javascript:
    Code:
    function addScript(js) {
        myHead = document.getElementsByTagName('head').item(0);
    
        newScript = document.createElement('script');
        newScript.setAttribute('type', 'text/javascript');
        newScript.setAttribute('src', js);
    
        myHead.appendChild(newScript);
    }


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
  •