I can not open local file ,meanwhile i use "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --allow-file-access-from-files on my shortcut of my google chrome.
the explorer tips the security mode had been closed and I can open a new window using js or href attribute.
But the question is :why each time I click the href ,it always open a blank page and nothing to display.so..
function copyUrl(obj)
{
var href = $(obj).attr("hreff");
var hideInput = $("#hidInputHref");
hideInput.val(href);
hideInput.select();
try
{
document.execCommand('copy');
var opener = window.open('file:////C:/windows');
// opener.document.write("<iframe src='c:\' width='100%' height='100%'></iframe>");
//var test = "<body><script>" +
// "alert(1);console.log(1);"
//"<" + "\/script><div>11111111111</div></body>";
////var stateObj = { foo: "bar" };
//opener.document.write(test);
//opener.history.pushState("", "page 2", "./a.html");
//opener.location.href = "www.baidu.com";
//opener.location.reload();
opener.opener.location.href = "C:\windows";
}
catch (err)
{
console.log(err);
}
}
C# code:
partsQueryList[i].ImageRefLink = "<a onclick='copyUrl(this)' hreff='" + "C:\\" + "' ><font color='blue'>ImageRefLink</font></a>";
btw,when I tried to use pushSate method ,it can push a new url to new window,but It can not solve crossdomain issue.so...how could I solve it?thanks!
You have 4 slashes instead of 3. Try this :
var opener = window.open('file:///C:/windows');
Note: Also C:/windows doesn't seem like a valid file. Try with a valid file name.
Check this post for more help : Open a local HTML file using window.open in Chrome
Related
I need to rename files using Photoshop Script and the code works fine on Windows but doesn't work on Macintosh. The code runs without error but the files name stays the same on Mac OS. It changes the file name on Windows.
Hostscript Code:
function RenameTest(){
var fpath = Folder.myDocuments + '/test.rtf';
var nfile = File(fpath);
var nfile_newname = Folder.myDocuments + '/test.ini';
nfile.rename(nfile_newname);
}
Main.js Code:
csInterface.evalScript('RenameTest()');
Thanks for any help!
I found the solution if anyone needs it.
This code works in Windows but not on Mac:
function RenameTest(){
var fpath = Folder.myDocuments + '/test.rtf';
var nfile = File(fpath);
var nfile_newname = Folder.myDocuments + '/test.ini';
nfile.rename(nfile_newname);
}
This works on both Windows and Mac:
function RenameTest(){
var fpath = Folder.myDocuments + '/test.rtf';
var nfile = File(fpath);
var nfile_newname = 'test.ini';
nfile.rename(nfile_newname);
}
The nfile.rename must only be the file name and extension. Don't add the path.
I have looked at all of the questions around windows.locaton.href and windows.locaton.replace not working, but still can't figure out why this redirect is not working in JavaScript. There are two JS functions I am calling when a button is clicked with submit.
<input type="submit"
onclick="NotifyUserOfNewBudgets('#Field1');redirect2MainLookup('#primaryFilename');"
class="SaveChangeButton" value="Create New Budget">
The two functions are defined in Javascript as:
<script>
function NotifyUserOfNewBudgets(val) {
alert("New Budget will be saved. NewVal=" + val);
var ireturn;
document.getElementById("NewBudgetID").value = val;
document.getElementById("formMode").value = "Update";
}
function redirect2MainLookup(primaryFilename) {
var loc = window.location.pathname;
var host = document.location.host;
var dir = loc.substring(0, loc.lastIndexOf('/'));
//Replace the word Edit with blank so this redirects correctly
var newdir = dir.replace("NewBudget", "");
var newpath = host + newdir + primaryFilename;
alert('newpath location = http://' + newpath);
try {
windows.locaton.href = "http://" + newpath;
//window.location.replace('http://' + newpath);
} catch (err) { alert("Error: " + err);}
}
</script>
The error I get in the try()catch() is windows is not defined and then is stays on the same page. I get the same error using windows.locaton.replace() too. I have lots of pages doing redirects, can't figure out why this one fails.
You have a number of spelling mistakes. window is the object you are looking to reference. location is the property you are looking to access. Right now, you are using windows.locaton. windows is not a thing, nor is locaton. Keep an eye on undefined errors, they can tell you a lot about the state of your code.
My HTML application file F:\relroot\libname.lib\textapp.hta (name altered) contains the following function:
function fullNameOfFile(filename) {
var fso = newMedium(); return fso.GetAbsolutePathName(filename)
}
When I run the application via Open or double-click it in the directory,
fullNameOfFile("../etc.txt") returns "F:\relroot\etc.txt" [runs perfectly!].
When I run it via Open with:Microsoft HTML Apln Host, however:
fullNameOfFile("../etc.txt") returns "C:/Windows/etc.txt" [wrong number!].
How should I code to get to work regardless of how the application is run?
I think I might have "Aspie-rigged" a solution (or maybe two)
Apparently opening the HTML application via Open (or double-click) presets the "current" directory to the directory containing the app while opening via Open With:Microsoft® HTML Application Host uses a default directory (like «C:\WINDOWS\system32»)
var shell = new ActiveXObject("WScript.Shell");
var wasDir = shell.currentDirectory /* OPTIONAL: push original current directory
to allow restoration later */
var swDL = false; // for differences in device file format
var splitter = (swDL ? '/' : '\\') // foreslash v. backslash
var slashes = (swDL ? '///' : '//') /* slashes between scheme/protocol
and authentication/host */
var lhref = swDL ? unescape(location.href) : document.URL;
var newDir = lhref.slice(location.protocol.length + slashes.length,
lhref.lastIndexOf(splitter));
/*
// uncomment this block for an "inside window"
alert("Entering Directory: «" + wasDir + "»\n" +
"Protocol/Scheme: «" + location.protocol + "»\n" +
"Location HREF: «" + lhref + "»\n" +
"Trial Directory: «" + newDir + "»");
*/
shell.currentDirectory = newDir
It seems to work like a charm on my system (Dell PC, Internet Explorer/¿Edge). I threw in some comments as well in case the next user needs to tweak it for their system.
I have a trusted function that saves a file to my network printer. But it doesnt work, I get this error: "The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder."
This is my code:
var xerox = app.trustedFunction( function()
{
app.beginPriv();
var xeroxPath = "\\\out\\spool\\print\\Xerox\\";
this.saveAs(xeroxPath + this.documentFileName);
app.alert("PDF is sent to the printer",3)
app.endPriv();
});
Ok, I found the solution. In windows map the "\\out\spool\print\Xerox\" to a new network Drive. In my case I mapped it to X: so the code becomes:
var xerox = app.trustedFunction( function()
{ app.beginPriv();
var xeroxPath = "x:\\";
this.saveAs(xeroxPath + this.documentFileName);
app.alert("PDF is sent to the printer",3)
app.endPriv();
});
I am integrating JSF with Birt report and able to connect with IHub server from Java code. Also got all the reports file inside some particular folder and displaying the report file name it into the JSF Datalist .Now when anyone will click on report file name i am calling a JavaScript method which will display the parameters required for report generation and using below code
function displayParams(reportName) {
prmRptName = reportName;
param = new actuate.Parameter("panel");
console.log("Display Params"+param);
alert(param);
document.getElementById("reportsForm1:reportsTable").style.display = 'none';
param.setReportName("Applications/Sure Project/Report Designs/"
+ prmRptName);
param.submit(function() {
document.getElementById("backbutton").style.visibility = 'visible';
document.getElementById("run").style.visibility = 'visible';
});
// console.log("Display Params");
}
but this line of code
param = new actuate.Parameter("panel");
throwing exception
actuate.Parameter is not a constructor
Any idea what i am doing wrong . here panel is a id of DIV component which is inside the XHTML page
Issue is resolve ,cause of problem is Birt Server URL
i was trying this code
function initReportExplr() {
actuate.load("viewer");
actuate.load("parameter");
var reqOps = new actuate.RequestOptions();
actuate.initialize("http://locahost:8700", reqOps,
"administrator", "", "");
}
while it should be like this
function initReportExplr() {
actuate.load("viewer");
actuate.load("parameter");
var reqOps = new actuate.RequestOptions();
actuate.initialize("http://locahost:8700/iportal", reqOps,
"administrator", "", "");
}