how to include local js file

H

HopfZ

This bookmarklet tries to load a local js file to a page.

javascript:(function(){
var s=document.createElement('script');
s.setAttribute('src','file:///C:/abc.js');
document.getElementsByTagName('body')[0].appendChild(s);
})()

But it doesn't work in remote web-pages. Is there a way to make this
work? Or it's not allowed due to security reason?
 
U

Une Bévue

HopfZ said:
javascript:(function(){
var s=document.createElement('script');
s.setAttribute('src','file:///C:/abc.js');
document.getElementsByTagName('body')[0].appendChild(s);
})()

But it doesn't work in remote web-pages. Is there a way to make this
work? Or it's not allowed due to security reason?

are u sure the parenthesis are required arround function(){} ???

also why not adding this script into the head rather body ???

i neve used such a bookmarklet, then not tested.
 
H

HopfZ

HopfZ said:
javascript:(function(){
var s=document.createElement('script');
s.setAttribute('src','file:///C:/abc.js');
document.getElementsByTagName('body')[0].appendChild(s);
})()
But it doesn't work in remote web-pages. Is there a way to make this
work? Or it's not allowed due to security reason?

are u sure the parenthesis are required arround function(){} ???

function(){...}()
synatax error
 
T

toff

s.setAttribute('src','file:///C:/abc.js');

I believe this is a security feature of Javascript.

If you could write a remote script to include a file from the local
hard drive, you could steal just about anything from that hard drive.

A script can write to and read from cookies on the local hard drive,
for its own domain, but I think that's about it.
 
N

NeoAlchemy

Why don't you try using xmlhttprequest object to grab from the local
box

var xmlHttp = new XMLHttpRequest;
xmlHttp.open("GET", "/C:/abc.js", false);
xmlHttp.send(null);
return {url: url, content: xmlhttp.responseText;}

Note on IE7 you'll need to use their activeX XHR object
 
V

VK

This bookmarklet tries to load a local js file to a page.

javascript:(function(){
var s=document.createElement('script');
s.setAttribute('src','file:///C:/abc.js');
document.getElementsByTagName('body')[0].appendChild(s);

})()

But it doesn't work in remote web-pages. Is there a way to make this
work? Or it's not allowed due to security reason?

Bookmarklet (favlet) shares the same security zone as the current page
in the browser. So if you have a local HTML page currently displayed
in your browser (file:///...) then you should be able to use local
files in your bookmarklet as well (after security warning on IE /
privilege request dialog on Gecko). Otherwise withing the default
security settings you are out of luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top