0

on my website when button is clicked then other javascript should download from server and apply to current page.

is it possible to do that, could anyone please share some info on it.

Thank you

basically want i am trying to do is

<input type="button" class="btntab" onclick=\'$p.apply.javascript('+ v_id +',"'+v_url+'")\' value="'+lg('applyjava')+'" style="margin:10px 0px;" >

Above code will display the button and on click will call the function $p.apply.javascript with two parameters (ID and url to download the javascript)

here in below function

$p.apply.javascript(v_id, v_url){

Here i want to download the javascript and apply on current page...which is located at
    window.location = 'http://www.example.com/java.php?url='+ v_url;

}

what above function is doing is redirecting me to

http://www.example.com/java.php?url='+ v_url;

and displaying the javascript in browser. Instead i want to download this javascript and apply on current page (may be after page refresh or something)

Could any one please share some info if you have done something similar or know how to do this.

thank you...in advance

SmartDev
  • 481
  • 3
  • 11
  • 30

1 Answers1

1

You can use this function to load css or js file on the run

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}
Luis Tellez
  • 2,785
  • 1
  • 20
  • 28
  • tried this but does not work var filename = 'http://example.com/java.php?url=' + v_url; var fileref=document.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", filename); – SmartDev Feb 14 '13 at 12:00
  • sorry my mistake.. i was missing something... it works like charm....Thank you very much for your help... just want to check with you while loading this javascript can we show loading image over whole page.. if possible... – SmartDev Feb 14 '13 at 12:05