SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    WaterGlobe
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Questionn about "src"

    I know javascript is an object_oriented language, but I often see some scripts like "<SCRIPT LANGUAGE="javascript" src="http://some_web_address"></SCRIPT>", there is only a 'src' and no object, so I think it should be 'object.src='.

    Could you give any sugestion? Thanks for any help!

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    <script> is the object,
    and can be accessed by the getElementsByTagName("script" )

    you can change the src of your external js in IE using
    document.getElementsByTagName("script" )[n].src="newJS.js"
    You can also do it in NS but only to an empty script object......
    Code:
    <script type="text/javascript"></script>
    but as the page cache's its external js you cannot call the same js that you may have changed with perl or PHP ( a js refresh )

    Bit of a shame really, I made a really simple chat-box using perl to write mew messages to an external js, and using the method above refreshing the js and adding new messages to the screen with a innerHTML function.

    worked really well offline, no good online though!!!

    It would be really useful if there was a way this could be applied.
    Imagine the gaming, forum, chat potential!!!!!!!!!!!! all live and no page refresh!!
    Last edited by Markdidj; Oct 18, 2003 at 01:49.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Zealot Arkkimaagi's Avatar
    Join Date
    Mar 2002
    Location
    Lappeenranta, Finland
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Markdidj, well you could always use a small iframe to do the js loading bit. Also did you try the random number trick at the end of the js url? chat.js?id=123 (where id is an value that's never used and the number 123 is a random number to prevent it being cached). So you just add ?id=1245 at the end of your js url thus prevent it from being cached.

    edit:
    does innerhtml work with netscape?

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    innerHTML works with pretty much all browsers now, NS IE and Opera works fine.
    I tried the ?id=math.floor(math.random()*1000) but it doesn't work just in js, still reads from the cached js. I think that the iframe with a small piece of HTML including meta no-cache was probably the best suggestion given, then refreshing the iframe and reading the the js variables again. Bit long-winded and I still haven't tried it yet.
    I'm just easing my way into server-side programming while trying to continue with all the other projects!!! I'll b giving it another go in the near future.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought the question was a bit odd - until I read the answers.

    That's HTML there: <script> is a tag, 'src' is an attribute, referencing a script (url) stored as a separate file. All scripts now have their equivalent DOM object, but that's irrelevant.

    Could you give any sugestion?
    Have a beer and don't worry about it.
    ::: certified wild guess :::


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
  •