SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2004
    Location
    Europe
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I call a doc write from an external js?

    If I use
    <script type="text/javascript" src="myscript.js"></script>

    on my page can that script have document.write methods in it?

    I want to generate some site wide content (the links on every page) that is altered when I alter the myscript .js.

    Also, If I do that will the css rules that apply to the rest of the document apply to the html tags I've just generated with the .js script?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Yes and yes. You can do it like so:

    Any HTML file:
    HTML Code:
    <div>
    <script type="text/javascript" src="myWrite.js"></script>
    </div>
    myWrite.js:
    Code:
    document.write("<div class=\"whatever\">My text</div>");
    Your CSS rules should apply, but I should warn you: If scripting is disabled, your users will see nothing where the script is.

    Off Topic:

    I see that you're trying to find a way to maintain the same content sitewide. Is there a reason you don't want to use something like SSI or Dreamweaver's templates?

  3. #3
    SitePoint Addict
    Join Date
    Mar 2004
    Location
    Europe
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see that you're trying to find a way to maintain the same content sitewide. Is there a reason you don't want to use something like SSI or Dreamweaver's templates?
    I don't have Dreamweaver and I prefer to write my own code. I hate it's rollover scripts and whilst it'd be fine if you were less of a nitpicker for me its all a bit meh.

    I don't know about SSIs and I don't really want to be installing new stuff on my webspace.

    My site(s) will use HTML,CSS,JavaScript(minimal), PHP and mySQL. No more, I beseech you!

    Edit: Holy crapola! That is an amazing ability. css+javascript write for self made site wide content. This is faaaantastic. If scripts are disabled I can put in a noscript warning anyhow. If they want it they will enable it. Who disables javascript anyway? Netscape users probably :P

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Subjective Effec
    My site(s) will use HTML,CSS,JavaScript(minimal), PHP and mySQL. No more, I beseech you!
    Then why not just use PHP includes?

    Any PHP page:
    PHP Code:
    <div>
    <?php include('myfile.php');?>
    </div>
    Myfile.php:
    PHP Code:
    <?php
      
    echo('This is text in an included file.');
    ?>

  5. #5
    SitePoint Addict
    Join Date
    Mar 2004
    Location
    Europe
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't do this to me man. There are soooo many cool possiblities with these. So many. . .

    I most certainly will use php includes on my own site as it wont even matter if people have javascript disabled will it? Oh joy.

    But the site at the moment isn't mine and the javascript works fine. Of course of the owner says its okay I'll just swap file types. And it will be easy!!

    Oh joy of scripting languages. . .


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
  •