I use the same code(Except the height parameter) to open linked-in and twitter share windows
window.open(
url,
title,
'_blank,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,=no,width='
+ width + ', height=' + height + ', left=' + x + ',top=' + y
);
But they are replace each other and not opened in separate windows.
How do i open them in different windows.
The second argument to the window.open() function gives a name to the window being opened. If you use the same name as an existing window then that window is re-used. You set that argument from your title variable, so make sure your title is different for your Twitter and Linked-in windows and then they'll open in separate windows.
(If you want a new window every time then set the second argument as "_blank".)
Further reading: MDN's window.open() page
Related
Please explain the difference between document.hidden , the HTML5 Page Visibility API and document.hasFocus(). I am doing a project which pops HTML5 Desktop Notification when the tab is not focused. I am kind of confused which one to use.
The hidden attribute is defined like this:
On getting, the hidden attribute MUST return true if the
Document contained by the top level browsing context (root
window in the browser's viewport) is not visible at all. The attribute
MUST return false if the Document contained by the top level
browsing context is at least partially visible on at least one
screen.
If the defaultView of the Document is null, on getting, the
hidden attribute MUST return true.
The hasFocus method is defined like this
The hasFocus() method on Document objects must return true if
the Document's browsing context is focused, and all its
ancestor browsing contexts are also focused, and the top-level
browsing context has the system focus. If the Document
has no browsing context or if its browsing context has no
top-level browsing context, then the method will always return
false.
For example, if you open a page in a foreground tab, and then open another window, the tab will (or may) still be partially visible, so hidden returns false. However, the new window has focus, so hasFocus() returns false for the tab.
If you run the following snippet, the document inside the iframe will be visible but won't have focus (this stackoverflow page is focused instead):
document.body.innerHTML =
'<p>hidden: ' + document.hidden + '</p>' +
'<p>hasFocus: ' + document.hasFocus() + '</p>';
But in this other one, since you click the button inside the iframe, it is both visible and focused:
document.getElementsByTagName('input')[0].onclick = function() {
document.body.innerHTML =
'<p>hidden: ' + document.hidden + '</p>' +
'<p>hasFocus: ' + document.hasFocus() + '</p>';
};
<input type="button" value="Click me!" />
TLDR:
document.hidden: returns true if tab is open and is not at all visible. Opening another chrome window and covering the open tab would make it return true
document.hasFocus(): returns true if the tab is the open tab and no other window has focus. Opening a chrome window would make that window have focus, so the open tab in the background, although visible, would return false
I have an application where i am doing new tab pop-ups in internet explorer(8,10,11) using window.open(myurl)
The pop-up triggered by a website contains a URL which is another page of that website. Problem here is that when the pop-up takes place, same webpage opens as the one from where the pop-up is being initiated.
If i copy the URL from address bar of the pop-up window and close all windows and than open that URL in new window of internet explorer only than my required page opens in the pop-up window/tab.
(Note: Same application works perfectly fine in Mozila Firefox without any issue, but it is clients requirement to run my application in IE)
Following is a method which is doing the pop-up:
function handlePhonecallScreenpop(callF, callT, callA, custid, entityN) {
var extraqs = "cf=" + callF;
extraqs += "&ct=" + callT;
extraqs += "&cd=outd";
extraqs += "&ca=" + callA;
extraqs += "&cid=" + custid;
extraqs += "&en=" + entityN;
var url = webUrl() + "/main.aspx?etn=phonecall&pagetype=entityrecord&extraqs=" + encodeURIComponent(extraqs);
window.open(url, "callpop");
}
I'm guessing that you aren't setting a target window name. Which means that you're reusing the same target window for EVERY window.open() call. Try adding an arg to each of your calls:
window.open('firsturl', 'windowA');
vs.
window.open('secondurl', 'windowB');
You should see two different windows.
If you change the name to _blank it should always open in a new window.
window.open(url, "_blank");
I am using window.open() to open
http://twitter.com/share.. and
http://www.facebook.com/sharer.php...
to allow the user to post to their Facebook or Twitter accounts.
These popup windows appear correctly infront of my current Chrome or Safari windows.
However when I change the URL to another page on my current domain the popup window appears behind the current window instead of infront!? Same code, same function to open the window, just a different URL being passed to window.open().
I can't figure out why, I've tried everything, commenting out any javascript in the popup page or anything that might cause Chrome/Safari to think it's malicious.
Do these browsers detect the URL as being Facebook/Twitter and allow it to appear in front, and shove anything else to the back?
This is my function for opening the window
InfoOverlay.prototype.popupWindow = function(url, title, width, height)
{
var left = (screen.width/2) - (width/2);
var top = (screen.height/2) - (height/2);
var targetWin = window.open(
url,
title,
'toolbar=no, location=no, directories=no, alwaysRaised=yes, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left
);
// These 2 lines added on suggestion from commenter below
// (doesn't fix issue)
targetWin.blur();
targetWin.focus();
}
It could be that those pages you are popping open have code in them to focus themselves (e.g. window.focus();)
You should be able to do that in your code in the page that pops the window open, just make sure you give your window a name, then do WindowName.focus();
This quick mockup in html seems to work in IE9, Chrome, FF4 but not Safari (3.x on Windows I have)
<script>
var myWin
</script>
<button onclick="myWin = window.open('about:blank', 'foo', 'height=200,width=200,modal=yes,alwaysRaised=yes');">Show Window</button>
<button onclick="myWin.blur();">Blur</button>
<button onclick="myWin.focus();">Focus</button>
My htaccess file nomenclature creating problem in opening a window in IE
EDITED
I have to open a colour picker which needs t be opened in popup, and I have
window.open('picker.html', null, "help=no,status=no,
scrollbars=no,resizable=no,toolbar=
no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
my base url goes like this:
http://www.mydoamin.com/
and the htaccess file has rewritten the above url from http://www.mydomain.com/30/
but when i wish to open the popup in IE the htaccess doesnt work for it and gives me url as http://www.mydomain.com/30/picker.html
and hence i get msg as broken link or NOT FOUND
there is no such folder called "30" the path has to be like http://www.mydomain.com/picker.html
The rewrite rule of the particular page goes like this:
RewriteRule
^30/order-vinyl-banners.html
order_form.php?id=30 [NC]
why is it happening..
please help me to track it..
If you want to show http://www.example.com/picker.html, you need to tell the open() function so. Right now you're telling it "Open the URL picker.html relative to where I'm currently at", but you want "Open picker.html relative to the root". Try this instead:
window.open('/picker.html', null,
"help=no,status=no,scrollbars=no,resizable=no,toolbar=no"
+ move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
I use the following code to display a popup:
var win = window.openDialog("chrome://broceliand/content/view/popup/nameMapPopup.xul",
"",
"all=no," +
"titlebar=no," +
"chrome=yes," +
"toolbar=no," +
"dialog=no," +
"resizable=no," +
"modal=yes," +
"dependent=yes," +
"top="+popupY+"px," +
"left="+popupX+"px",
args);
On windows the popup is pretty clean. There are no common elements remaining.
But on linux le titlebar still remains and the popup is resizable.
Try setting the hidechrome attribute on the window element to true. See https://developer.mozilla.org/en/xul/window
That might be because on Linux the window decorator is responsible for the titlebar. This can even be a seperate program to the window manager.
Does the popup need to be as a seperate window? Perhaps panel is really what you are looking for.