I'm trying to launch a HTML file in firefox automatically
Our company has IE set as the default and this file is meant to launch in firefox to work properly
This is the code I have to check that, but for some reason it doesn't want to work properly
The filepath is correct which was the first thing I thought of
Can anyone assist?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="opener_files/opener.css" media="screen" type="text/css">
<script type="text/javascript">
function codeAddress(){
if (browserName = "Internet Explorer");
var shell = new ActiveXObject("WScript.Shell");
shell.run('"Firefox" "file:///Mel19a001ppn/transfer/L&D_LT&S/SimonW/Sean/DEBT T1 Re-design/SD_Debt_Systems_Introduction/intro.html"');
}
window.onload = codeAddress;
window.setTimeout(CloseMe);
function CloseMe()
{
window.open('','_parent','');
window.close();
}
</script>
</head>
</html>
Edit:
I played around with it some more, and got this to run and launch firefox
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="opener_files/opener.css" media="screen" type="text/css">
<script type="text/javascript">
function codeAddress(){
if (navigator.userAgent.indexOf("MSIE") != -1 ) {
var shellApp = new ActiveXObject("Shell.Application");
var commandtoRun ="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
shellApp.ShellExecute(commandtoRun,"","", "open", "3");
}
}
window.onload = codeAddress;
window.setTimeout(CloseMe);
function CloseMe()
{
window.open('','_parent','');
window.close();
}
</script>
</head>
</html>
That opens firefox properly but now I can't work out how to load the filepath that I have
Any ideas?
You can get the installation path of FireFox from the Windows Registry, like so:
var shell = new ActiveXObject("WScript.Shell"),
cVer = shell.RegRead('HKLM\\SOFTWARE\\Mozilla\\Mozilla Firefox\\currentVersion'),
FF = '"' + shell.RegRead('HKLM\\SOFTWARE\\Mozilla\\Mozilla Firefox\\' + cVer +'\\Main\\PathToExe') + '"';
And then try to run FireFox:
shell.Run(FF + ' "\\\\Mel19a001ppn\\transfer\\L&D_LT&S\\SimonW\\Sean\\DEBT T1 Re-design\\SD_Debt_Systems_Introduction\\intro.html"');
Related
I want to download "example.mp4" to my iPhone using FileSaver.js.
But when I download it in chrome, it downloads the file as "document".
donwload in chrome
Does anyone know how to solve this problem?
my code
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Download Sample</title>
<script src="js/FileSaver.js"></script>
<script type="text/javascript">
const contents_url = "a.mp4";
const file_reader = new FileReader();
var out;
file_reader.onload = function (e) {
saveAs(e.target.result, "example.mp4");
}
function handleDownload() {
out = new Blob([contents_url], { type: 'video/mp4' });
file_reader.readAsDataURL(out);
}
</script>
</head>
<body>
Download
</body>
</html>
my environment
iOS : 14.1
chrome version : 86.0.4240.93
things to try
I tried downloading in safari and was able to download in "example.mp4".
I've been having trouble with Firefox not executing JavaScript files that were loaded dynamically via an external script.
Let me explain.
I have the following HTML file:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Restive.JS</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="assets/js/load.js"></script>
</head>
<body>
<h1>Loading JavaScript</h1>
</body>
</html>
Inside my load.js file, I have the following code:
document.addEventListener("DOMContentLoaded", function() {
function loadScript(url) {
var script = document.createElement("script");
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
var list_arr = ['assets/js/test1.js', 'assets/js/test2.js'];
for (var i = 0; i < list_arr.length; i++) {
loadScript(list_arr[i]);
}
});
And inside test1.js and test2.js, I have console.log('test1.js is loaded!'); and console.log('test2.js is loaded!');.
The problem is that test1.js and test2.js are loaded (I can see both files in the <head> via inspection), but they are never executed (because no messages appear in the console log).
However, when I change the format of script reference in my original HTML by inlining the JavaScript i.e. changing from this:
<script type="text/javascript" src="assets/js/load.js"></script>
to this:
<script>
document.addEventListener("DOMContentLoaded", function() {
function loadScript(url) {
var script = document.createElement("script");
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
var list_arr = ['assets/js/test3.js', 'assets/js/test4.js'];
for (var i = 0; i < list_arr.length; i++) {
console.log('i = ' + i);
loadScript(list_arr[i]);
}
});
</script>
Then the scripts are loaded and executed.
I don't see this behaviour in Chrome or Safari, only Firefox. Also, inlining is not an option because this functionality is built-in to a library that users will have to reference via an external link.
Is this a problem that is fixable?
EDIT
I'm on a Mac OSX 10.10.5 using Firefox 46.0.1
I am trying to achieve something like, www.example.com/en/test/page.html will load the frameset of www.example.com/2.html.
Which I am able to do.
But now once 2.html is loaded in frameset I want to replace .html" to .html" target="_top".
So that all the links present in 2.html would be opened in the parent window instead of frameset itself.
<!DOCTYPE html">
<html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Test Page</title>
<script>
(function divert()
{
var urlString = parent.document.URL;
var a1 = new RegExp("/en/test/page");
if(a1.test(urlString)) {document.write('<frameset cols="100%" rows="100%"><frame src="http://www.example.com/2.html"></frameset>');}
else{document.write('<frameset cols="100%" rows="100%"><frame src="http://www.example.com/3.html"></frameset>');}
var str = document.getElementById("demo").innerHTML;
var res = str.replace('.html"', '.html" target="_top"');
document.getElementById("demo").innerHTML = res;
})();
</script>
</head>
<body onLoad="divert()"></body>
Hi #Vinod you can use target="_parent"if you have only 2 level of frame-set or just want to open the link to the parent frame only..
Or to open the link to the current page you can use target="_top"
You can read more about it here
UPDATE:
You can also use JavaScript to detect if page is loaded inside a frame and than add target to the links pragmatically..
You can use window.location.origin and parent.window.location.origin to detect if you are in the frame
And than you can use following code to add target using JavaScript
using jquery:
$(document).ready(function(){
$('#link_other a').attr('target', '_blank');
});
without using jquery
window.onload = function(){
var anchors = document.getElementById('link_other').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
}
}
<!DOCTYPE html">
<html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Test Page</title>
<script>
(function divert()
{
var urlString = parent.document.URL;
var a1 = new RegExp("/en/test/page");
function targetUrl(){
var links = document.getElementById("demo").contentDocument.documentElement.getElementsByTagName('a');
for(var i =0; i<links.length; i++){
links[i].target = '_parent';}
}
if(a1.test(urlString)){document.write('<frameset cols="100%" rows="100%"><frame id="demo" src="http://www.example.com/2.html"></frameset>');}
else{document.write('<frameset cols="100%" rows="100%"><frame id="demo" src="http://www.example.com/3.html"></frameset>');}
document.getElementById("demo").onload= targetUrl;
})();
</script>
</head>
<body></body>
</html>
in Opera when I serialize an xml doc, it returns the string with the XML Declaration added to it. In Firefox and Chrome this dose not occur, and i would like Opera to return same results as Firefox and Chrome.
http://jsfiddle.net/superbDeveloper/Qst5e/9/ (JavaScript Code below)
JavaScript Code
//test xml serializer
var s = new XMLSerializer();
var d = document;
var str = s.serializeToString(d);
console.log("1) serializeToString ");
console.log(str);
Results in Firefox
1) serializeToString
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta content="text/html; charset=UTF-8" http-equiv="content-type" /> <title> - jsFiddle demo by superbDeveloper</title> <script src="/js/lib/mootools-core-1.4.2-full-nocompat.js" type="text/javascript"></script> <link href="/css/normalize.css" type="text/css" rel="stylesheet" /> <link href="/css/result-light.css" type="text/css" rel="stylesheet" /> <style type="text/css"> </style>.....
Results in Opera
1) serializeToString
<?xml version="1.0"?><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title> - jsFiddle demo</title>
<script type="text/javascript" src="/js/lib/mootools-core-1.4.2-full-nocompat.js"/>
<link rel="stylesheet" type="text/css" href="/css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="/css/result-light.css"/>
<style type="text/css">
</style>...
Notice the XML Declaration <?xml version="1.0"?> has being added in Opera browser. Is there a way of stoping Opera from adding the XML Declaration? or how can one remove the XML Declaration? I thought of using substring but its not really an elegant solution.
Well, at this point what you have is a string, so using string methods is as elegant as it gets :)
I'm not aware of any other way to do it.
This problem is only in non-IE browser. Use documentElement solution.
xmlData = jQuery(xmlData);
var oSerializer = new XMLSerializer();
if (typeof xmlData[0].documentElement !== 'undefined') {
var xmlString = oSerializer.serializeToString(xmlData[0].documentElement);
} else {
var xmlString = oSerializer.serializeToString(xmlData[0]);
}
I have a index.html page, which contains a buttonid="my-btn"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My INDEX PAGE</title>
</head>
<body>
<div id="my-canvas"></div>
<br><input type="button" id="my-btn" value="OPEN NEW WINDOW"/>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/raphael.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/my.js"></script>
</body>
</html>
js/my.js invoke createCircle function from my-graph.js, and handles button click event, when my-btn button is clicked, a new browser window will be popped up with a new page (test.html)
my.js:
MyTest.createCircle();
$('#my-btn').click(function(){
window.open('test.html', 'testwindow');
});
my-graph.js:
MyTest= function(){
var paper = Raphael("my-canvas", 320, 200);
var st=paper.set();
return {
createCircle: function(){
st.push(
paper.circle(10, 10, 5),
paper.circle(30, 10, 5)
);
}
getSet: function(){
return st;
}
};
}();
The new page(test.html) opened in new browser window:
test.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TEST</title>
</head>
<body>
<div id="my-name"></div>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/test.js"></script>
</body>
</html>
In the new page, test.js will be invoked and I want to pass the Paper.set() st from my-graph.js to this test.js and output st.length as the content of this page
js/test.js
$(document).ready(function(){
var st=MyTest.getSet();
$("#my-name").append("<strong>"+st.length+"</strong>");
});
But I always get 0 length of the st in new popped up page. Why?
so your opening a new page with script references to the same code
as the other page
That dosent mean that they have the same state.
The new page will get its own state from evaluating
the script itself
what you can do is save the reference that
var w = window.open('test.html', 'testwindow');
returns you can use that for calling a function on your new page
or you can yost do all the code on the start page with jquery
and useing that window object as your context
var w = window.open('test.html', 'testwindow');
$(w).ready(function() {
$("body", w).append(mystuff);
});
raphael objects are set to a paper i think not shure what will
happend when passing them betwen papers :S