-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Root relative paths not behaving as expected #2242
Comments
Please use nodejs to introduce the way |
Thanks for the response, although my intention is to keep my app source platform agnostic in case we need to run it as client-server. I still think this is a valid problem but for now I have altered links to relative paths. |
I know what you mean. This article can help you: or set : new BrowserWindow(options) I found,use < iframe src=A.html>,In A.html Can use “script ” Import. I use the Google translation, tired :) |
I found this solution for whomever it may concern: function createWindow() {
const WEB_FOLDER = 'web';
const PROTOCOL = 'file';
electron.protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {
// // Strip protocol
let url = request.url.substr(PROTOCOL.length + 1);
// Build complete path for node require function
url = path.join(__dirname, WEB_FOLDER, url);
// Replace backslashes by forward slashes (windows)
// url = url.replace(/\\/g, '/');
url = path.normalize(url);
console.log(url);
callback({path: url});
});
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false
}
});
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: 'index.html',
protocol: PROTOCOL + ':',
slashes: true
})); |
Thank @bertyhell! I was having the same issue and that solution worked perfectly. |
Thanks @bertyhell, I have been working one week trying to get this! Kudos! :-D |
Thanks @bertyhell , but I tried it at BTW, is there any way to set the root path by the configure like I'm now trying to use Consider that if we use some web-server to serviced the built-project, |
Well, I forgot to call the |
@bertyhell - I tried to use your solution, but when I'm using interceptFileProtocol, even when all I do is calling callback(request.url) I'm getting a warning and an error on the renderer process:
It seems like chrome is blocking the loading of a local index.html due to security reasons, which prevents loading the site... |
It appears that using domain relative paths the following does not behave as expected:
Each of these resolve to:
file:///C:/js/ext/webcomponents-lite.js
file:///C:/html/htmldependencies.html
file:///C:/html/jsdependencies.html
Am I missing something here?
Is there a special token or configuration to use to get this working as it should?
Thanks
The text was updated successfully, but these errors were encountered: