Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reload a js file and nothin else....

    Well, i just want to reload my js file nothing else

    thanks for any help

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ask in the DOM forum about inserting a "new" script tag. It may be possible to insert one and that would cause a copy of the script to be loaded but whether it would use a fresh copy retrieved from the server or the copy already cached is anyone's guess.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How I would do it.

    <script id="test" src="test.js" type="text/javascript"></script>
    <script>
    function test()
    {
    scriptBlock=document.getElementById('test');
    scriptBlock.src=scriptBlock.src;
    }</script>

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    I would personally wrap everything except global variable and function declarations in a function, and call that function again if needed, instead of trying to load the script again. There's no guarantee toward whether the file will be called from cache or reloaded at all, and there is no guarantee that the file will be executed again if it is in fact reloaded. Op7 before 7.5 did neither load the file, not execute the script if you wrote it into the file dynamically. Saf1.2 still does neither. Ie5m does only load the file if the script element is written through innerHTML instead of dynamically created.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    migth be me that are wrong here but reload ain't that simply when it calls the file from whatever source it find it at.
    and refresh is when it force downloads a new copy of the requesten file?

    anyway perhaps I should write 'IE6 Scripter ONLY' in my sig

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the thing is that when i just chage the src of the script element it doesnt execute the js file again.

    then i have to reload the whole page.... which takes tooo long in some cases

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The src of scripts is read only for practical reasons. You have to create a new script element for it to load anew, in the browsers that does that.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how?

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    For iew, moz and op7.5:
    Code:
    var
        oScript=document.createElement('script');
    oScript.type='text/javascript';
    oScript.src=sAddress;
    document.getElementsByTagName('head').item(0).appendChild(oScript);
    For iem:
    Code:
    var
        oDiv=document.createElement('div');
    oDiv.innerHTML='<script type="text/javascript" src="'+sAddress+'"><\/script>';
    For Saf1.2 (only works on files in the same domain):
    Code:
    var
        oFile=new XMLHttpRequest;
    oFile.open('GET',sAddress,false);
    oFile.send('');
    eval(oFile.responseText);
    The saf code also works in moz, but may crash the browser in some cases.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks alot


  •  

    Posting Permissions

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