I am trying to open new tab using Window Open under javascript as below:
$.ajax({type: "POST",url:"GetData.php?m="+e.series.key,
dataType: "json"}).done
(function( FolderPath )//i get the folder path under this variable
{
OpenInNewTab(url);//url="file://///NetworkSharePath/Folder1/Folder2" -->URL Value
});
function OpenInNewTab(url) {
var win = window.open(url , '_blank');
win.focus();
}
Observation:
It opens a new Tab but not the desired Path.
Note:
I have added Local Links for Chrome as an extension.
When i paste the same url in browser, its able to load the directory structure
When i try to open http://www.google.com, it redirects the new tab correctly.
Not sure what am I missing, please share inputs
Related
I'm a noob. I have a code to simulate a terminal. This is it: https://codepen.io/isdampe/pen/YpgOYr.
Command:
var coreCmds = {
"clear": clear
};
Answer (clear the screen):
function clear(argv, argc) {
termBuffer = "";
return "";
}
As mentioned in the title, how to add a command to launch a new tab in the browser (to google.com for example, or anywhere else)?
Thank you.
window.open();
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
Here's an example:
window.open("https://www.google.com");
Structure:
window.open(URL, name, specs, replace)
Since you want to open a new tab in browser, you should put _blank in name. However, this is the default.
What would your code look like?
This is a rough outline, replace variable names and arguments as you like
var var_name = {
"new window": new_window
};
function new_window(arguments) {
termBuffer = "";
return window.open(arguments);
}
I hope this helps :D
Use the window.open method with an input URL.
window.open('https://google.com')
This would open a tab to https://google.com.
I have a .php file running that is generating a downloadable file; when the .php file runs it opens a tab in the browser. Occasionally the .php file takes up to 15 seconds depending on the conditions to create the file.
I would like to know when this tab is open generating the downloadable file and when it closes. This way I can have some sort of loading message displayed while the file is being generated. When the .php file is done creating the file it automatically closes the tab.
Code:
var win = window.open(download, '_blank'); //opens the php file which generates the file.
if (win)
{
win.focus();
//have some sort of message stating to wait for the file to download here and then close it when the php file finishes running.
}
else
{
alert("Please allow popups.");
}
closePopup2();
I would suggest not opening a PHP file in a new tab, but using XMLHttpRequest(), you can find a guide on how to use it on MDN
You can use it like this:
function reqListener () {
console.log(this.responseText); // Will log full output of page
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", download);
oReq.send();
Give your window a unique id so the script will know which one to check (maybe needs to be random if opened/closed multiple times). I don't know if you need to focus, and popup permission is for you to figure out, but I think following should work:
var win = window.open(download, 'windowID', 'width:300px;height:300px');
win.document.write("<p>One moment please!</p>");
win.focus();
var test = setInterval(function() {
if(win.closed) {
clearInterval(test);
// do you stuff here after window closed
}
}, 500);
I am new to chrome extensions and trying to work this out.
When I click on the extension button, it should copy the current url and open google.com in a new tab then place this url in searchbox or console print the url. Basically,
Copy the url to new tab, which can be used to perform further actions.
We can open new tab using.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "http://www.google.com"
chrome.tabs.create({ url: action_url });
});
Not sure how to call functions/perform actions after the new tab openx
You want to do two things :
1) Copy the current url.
2) Do something with it in the new tab opened with google.com as the url.
You can get the current url in javascript using: window.location.href
You have a callback function for chrome.tabs.create(object createProperties, function callback) as here and use this callback function ( which is called once the tab is successfully created) to pass current url to content script using message passing.
copy the current url using ** window.location.href**
make a new string by concating the string obtained in step 1 with https://www.google.co.in/search?q= i.e new string would be https://www.google.co.in/search?q=www.google.com (if you want to search google.com in new tab)
write a javascript function in content script to open new tab and search for the string obtained in step 2.
I already created an extension that does the following:
When I run Thinderbird with the command line thunderbird -MyCustomParam1 "12345" my extension will open a compose window and add the parameter "12345" to the window.
Some code that I use:
// In the calling code
var args = {
param1: 12345,
};
args.wrappedJSObject = args;
var watcher = Components.classes["#mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
watcher.openWindow(null, url, windowName, features, args);
// In the window code
var args = window.arguments[0].wrappedJSObject;
Of course using the correct url and features.
Now I want to do the same, but for the message window and with am eml file that is choose.
You can open an eml file from the command line like this: Thunderbird test.eml (this will open the mail in a new window).
What I want is the following:
Thunderbird test.eml -MycustomParam1 "1234" should open the mail, and add the param "1234" to screen, so I can access it in the document window, just like example 1.
So basically I want something like watcher.openWindow, but with a given eml file.
Any ideas?
You can see how this is done in the MsgOpenFromFile function, it is being called for the File / Open Saved Message menu item. You basically have to take the eml file (get an nsIFile instance from file path), turn it into a URI and then change the query string before opening a message window:
uri.QueryInterface(Components.interfaces.nsIURL);
uri.query = "type=application/x-message-display";
watcher.openWindow(null, "chrome://messenger/content/messageWindow.xul", "_blank",
"all,chrome,dialog=no,status,toolbar", uri);
I am writing code to download a PDF file using window.open(). I am passing the URL path of the pdf file on a server.
window.open(url, name, "width=910,height=750,scrollbars=yes");
I want to check if the downloading of file is successful or not. What is the return type of window.open()?
I tried like this
try
{
window.open(url, name, "width=910,height=750,scrollbars=yes");
alert("success");
}
catch(e)
{
alert("failer");
}
When I change the URL to a wrong URL, it shows the same result as a success.
http://www.javascripter.net/faq/openinga.htm
The return value is the reference to your new window. You can use
this reference later, for example, to close this window
(winRef.close()), give focus to the window (winRef.focus()) or perform
other window manipulations.
Window.open either returns a handle to the new window opened or null, it will not tell you if the page within the window loaded successfully. If you where opening an html page (from the same domain) you could use this to look into the document
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";