Am writing javascript variables that can be assessed from other javascrpt files loaded in a browser window.
my script is as follows
window.mysiteVars = {};
window.mysiteVars.myDir = function(){
if(document.location.href.indexOf('localhost') > -1){
// i am on localhost
return 'http://localhost/mysite/';
}else if(document.location.href.indexOf('mydomain.com') > -1){
// i am on my remote host
return document.location.origin+'/';
}else{
// i am accessing localhost from another computher in the network
return document.location.origin+'/mysite/';
}
}
window.mysiteVars.dir1 = window.mysiteVars.myDir()+'dir1/';
window.mysiteVars.dir2 = window.mysiteVars.myDir()+'dir2/';
if i do console.log(window.mysiteVars.dir1) or even console.log(mysiteVars.dir1) in any of the javascript files loaded in the page it will returns as expected in chrome, firefox and safari, but in internet explorer it outputs "undefineddir2/
i.e. it returns undefined for the first property of mysiteVars which is a function.
please how do i fix this problem?
thanks.
I am using lwip tcp/ip stack with a STM32F4 to host a small configuration website for my device. I am refreshing a hidden iframe on my page to get updated SSI values and then using them in my tmp variable to update a graph. The code below works great in IE but in Firefox and Chrome tmp only gets a value once even though the temptemp element is getting updated values from my firmware.
var iframe = document.getElementById("iframeID");
var innerdoc = (iframe.contentWindow || iframe.contentDocument);
if(innerdoc.document)innerdoc = innerdoc.document;
(function worker() {
$.ajax({
url: 'data.shtml',
complete: function() {
document.getElementById("iframeID").contentWindow.location.reload();
setTimeout(worker, 1000);
tmp = innerdoc.getElementById("temptemp").value;
}
});
})();
"Domains, protocols and ports must match."
Have you checked the console for errors, when running this in Firefox and Chrome? I think you're being told that you cannot access unsafe JavaScript. Perhaps Internet Explorer is just fine with being insecure about how it runs JavaScript.
I'm currently trying to build a firefox extension that determines a proxy for each http request based on Regular Expressions. The Proxy that has been used for loading a page should be remembered for any new request coming from that page, ie. any image/script/css file needed for that page, any outgoing links or ajax requests. That also means that the proxy needs to be remembered for each open tab.
This is where I run into my problem: Up until now I tried to mark each open tab by inserting a unique id as an attribute of the browser element of the tab, and looking for this id in an implementation of the shouldLoad() method of nsiContentPolicy. The code I'm using for this is shown below, and it was extracted from the addon sdk's getTabForContentWindow method in tabs/utils.js.
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra)
{
var tabId = null;
if (!(context instanceof CI.nsIDOMWindow))
{
// If this is an element, get the corresponding document
if (context instanceof CI.nsIDOMNode && context.ownerDocument)
context = context.ownerDocument;
// Now we should have a document, get its window
if (context instanceof CI.nsIDOMDocument)
context = context.defaultView;
else
context = null;
}
let browser;
try {
browser = context.QueryInterface(CI.nsIInterfaceRequestor)
.getInterface(CI.nsIWebNavigation)
.QueryInterface(CI.nsIDocShell)
.chromeEventHandler;
} catch(e) {
this.console.log(e);
}
let chromeWindow = browser.ownerDocument.defaultView;
if ('gBrowser' in chromeWindow && chromeWindow.gBrowser &&
'browsers' in chromeWindow.gBrowser) {
let browsers = chromeWindow.gBrowser.browsers;
let i = browsers.indexOf(browser);
if (i !== -1)
tabId = chromeWindow.gBrowser.tabs[i].getAttribute("PMsMark");
}
return CI.nsIContentPolicy.ACCEPT;
}
This works fine for any load that does not change the displayed document, but as soon as the document is changed(ie. a new page is loaded), the variable browser is null.
I have looked at the other mechanisms for intercepting page loads described on https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Intercepting_Page_Loads , but those seem to be unsuitable for what I want to achieve, because as far as I understand they work on HTTP requests, and for a request to exist, the proxy already needed to be determined.
So, if anybody knows a way to catch imminent loads before they become requests, and at the same time, it's possible to find out which tab is responsible for those loads-to-be, I'd be glad if they could let me know in the answers! Thanks in advance!
https://developer.mozilla.org/en-US/docs/Code_snippets/Tabbed_browser#Getting_the_browser_that_fires_the_http-on-modify-request_notification
Components.utils.import('resource://gre/modules/Services.jsm');
Services.obs.addObserver(httpObs, 'http-on-opening-request', false);
//Services.obs.removeObserver(httpObs, 'http-on-modify-request'); //uncomment this line, or run this line when you want to remove the observer
var httpObs = {
observe: function (aSubject, aTopic, aData) {
if (aTopic == 'http-on-opening-request') {
/*start - do not edit here*/
var oHttp = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel); //i used nsIHttpChannel but i guess you can use nsIChannel, im not sure why though
var interfaceRequestor = oHttp.notificationCallbacks.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
//var DOMWindow = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow); //not to be done anymore because: https://developer.mozilla.org/en-US/docs/Updating_extensions_for_Firefox_3.5#Getting_a_load_context_from_a_request //instead do the loadContext stuff below
var loadContext;
try {
loadContext = interfaceRequestor.getInterface(Components.interfaces.nsILoadContext);
} catch (ex) {
try {
loadContext = aSubject.loadGroup.notificationCallbacks.getInterface(Components.interfaces.nsILoadContext);
//in ff26 aSubject.loadGroup.notificationCallbacks was null for me, i couldnt find a situation where it wasnt null, but whenever this was null, and i knew a loadContext is supposed to be there, i found that "interfaceRequestor.getInterface(Components.interfaces.nsILoadContext);" worked fine, so im thinking in ff26 it doesnt use aSubject.loadGroup.notificationCallbacks anymore, but im not sure
} catch (ex2) {
loadContext = null;
//this is a problem i dont know why it would get here
}
}
/*end do not edit here*/
/*start - do all your edits below here*/
var url = oHttp.URI.spec; //can get url without needing loadContext
if (loadContext) {
var contentWindow = loadContext.associatedWindow; //this is the HTML window of the page that just loaded
//aDOMWindow this is the firefox window holding the tab
var aDOMWindow = contentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
var gBrowser = aDOMWindow.gBrowser; //this is the gBrowser object of the firefox window this tab is in
var aTab = gBrowser._getTabForContentWindow(contentWindow.top); //this is the clickable tab xul element, the one found in the tab strip of the firefox window, aTab.linkedBrowser is same as browser var above //can stylize tab like aTab.style.backgroundColor = 'blue'; //can stylize the tab like aTab.style.fontColor = 'red';
var browser = aTab.linkedBrowser; //this is the browser within the tab //this is what the example in the previous section gives
//end getting other useful stuff
} else {
Components.utils.reportError('EXCEPTION: Load Context Not Found!!');
//this is likely no big deal as the channel proably has no associated window, ie: the channel was loading some resource. but if its an ajax call you may end up here
}
}
}
};
For some reason when I am trying to debug my site in VS I get the error
JavaScript runtime error: Unable to set property 'value' of undefined
or null reference
when using a date picker. I can hit continue and everything works perfectly fine. If I run the site without debugging everything works fine, the exact same code running in production works fine so why is VS complaining about this only when I debug?
function SetDate(formName, id, newDate, postBack) {
var theform = document.getElementById(formName);
popUp.close();
theform.elements[id].value = newDate;
if (id = "txtDate3") {
theform.elements['txtDate4'].value = newDate
}
if (postBack) __doPostBack(id, '');
}
if (id = "txtDate3")
assignment is improper here, use conditional
if (id == "txtDate3")
or
if (id === "txtDate3")
I want to see my specific folder on IE window.i use window.open(); and then i get an error "Access denied".I gave "everyone" permission on this folder and share it.
var oShell = new ActiveXObject("Scripting.FileSystemObject");
var Path="C:\\test\\"+crmForm.ObjectId;
if (! oShell.FolderExists(Path) )
{
oShell.CreateFolder(Path)
}
crmForm.all.new_paylasim.DataValue=Path;
var urlField =crmForm.all.new_paylasim;
urlField.style.color = 0x0000ff;
urlField.style.textDecorationUnderline = true;
urlField.style.cursor = "hand";
urlField.ondblclick = function() {
var url = urlField.DataValue; // Or get it from somewhere else
if (url != null && url.length > 0) {
window.open(url);
}
}
What's solution?
You have to problems
the security model of IE has changed and window.open with a local file path does IMHO not work anymore. See also Ie 8.0 Access Denied When Trying To Open Local Files
Your file uri is not correct. It should be either file:///C:/myfile.txt (which doesn't work anymore) or file://server/share for a network share. See http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
Create a network share for the folder you would like to open.