I have a program that is written in CSS/HTML/JavaScript all inline, and opened directly from the HTML file (no web URL). Right now, everyone I work with has their browser set to open any links in a new tab in the same window, which makes the program useless, as it is form that is filled out manually, meant to be on a second monitor.
Right now, I have the window.resizeTo(); and the window.moveTo(); functions working properly IF the open in tabs is changed to open links in new window, but I cant walk around doing that to over 500 computers (no exaggeration on the amount), not to mention, any changes to the settings are reset afte the computers are reset.
When I try the window.open();, it just opens up a blank page in a new window after the .html file is opened, I need it to open itself in a new window, and then resize/move after.
Use window.open(...) with the height and width parameters set. This will force the link to open in a new window:
Share Page
Demo
You can pass a URL to window.open() to open that URL.
You can pass the current URL using location.href.
You can also specify a size and location directly in the third parameter.
Opening a page on tab or a separate window is browser specify feature, and it cannot be controlled by a Web Application.
window.open() will open a popup window and can open any URL you specify when provided:
window.open('openthispage.html);
window.open(URL,name,specs,replace)
add the URL of the program and it should work
Related
The problem is when calling window.open(url, name) for a specific page, it is always opened in a new window, instead of the SAME one. In other words, every time this statement is executed, a new window is opened, while what I want is only ONE new window is opened and all the following calls will open the page in that new window. The name parameter in this javascript statement doesn't work for this case obviously. It only happens with IE11(Couldn't try other versions of IE).
When I tried opening window of my own pages, it worked as expected. But that specific page doesn't. That page is on the same host but out of my control. I don't know what exactly it does. The only thing I know is it relaxes document.domain. But even if I change the domain of the main page to be the same as that page's, it still doesn't work.
Does anybody know what's the root cause?
Thanks in advance!
The problem might be due to Internet Explorer settings.
Under Internet Options
Click Settings under Tabs
Under When a pop-up is encountered:, select Always open pop-ups in a
new tab
Under Open links form other programs in:, select A new tab in the
current window
to do that you want
window.location not open
open will open a new window/tab
EG
window.location = "http://www.google.com"
to navigate to google.com in the same window/tab
I'm stuck using a CMS that only gives me the ability to modify the content of the <body>, so when I want to redirect people, I've used this
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
So, yes, the page loads first, and then 5ms later, the redirect happens, and it's worked for all intensive purposes. Now, I'm wondering if I can use javascript to do something else.
Is it possible to open a new browser tab, with a specified URL, and then redirect the user back to the previous page, through Javascript?
Many thanks, SO.
EDIT - Whether it opens a new window or tab, to be honest, is not as important as it actually functioning. I need Javascript to determine the prior page (if possible), then open a new window/tab to a URL I specify, and then redirect the current window/tab to it's prior page. Some are saying that window.open only works on a click event, which will not work for what I am trying accomplish either... just fyi.
So, literally, without clicks, I need Javascript to do the following -
Determine the prior/previous/last page the user came from, store it as a variable
Open a new window or tab, to a specified URL
window.location back to the prior page, which I stored as a variable
Hope that makes sense.
Depending on the user's browser setting using window.open can open the new window in a new tab instead but you CANNOT directly control this through the browser. It is all down to the user's settings.
To open a new window:
window.open("http://www.google.com", "windowName", "window options (optional parameter)");
Then simply use:
history.back();
You can also use the referer property:
var previousUrl = document.referrer;
For more info on window.open, see: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
For more info on the document.referrer property, take a look at: http://www.netmechanic.com/news/vol4/javascript_no14.htm
I have created a jsp for external clients of my application to use to link to the web client. They can specify which client they are in the URL so that when the link opens a window it is named and any other links from that client will open in the same window. Here's an example URL:
mysite.com/redirect.jsp?fromClient=mine&page=awesome
The problem is that when you click on this link, for example from an email digest, it opens the redirect.jsp page which uses window.open() to open the desired page. From the above link, the page that would open would be:
mysite.com/index.jsp?page=awesome
So then I have two pages open, when really I only want one. And since I'm not using javascript to open the first page (it's a link), I can't use window.close() to close it. I've tried working around using window.open('','_parent','') and window.open('','_self','') but neither works.
I know there has to be a better way to redirect than to open a second window from my jsp page, but I don't know what that better way is. Thoughts?
EDIT
Primary goal is for users of external clients to be able to click links in that client and have all the links take them to the same window/tab in a browser. I'm using window.open right now because I can parse the link and get the client name and then supply that in the window.open function.
EDIT 2
I always end up being too vague in these questions. Ok, here's the setup:
An email digest contains a link that looks like
mysite.com/redirect.jsp?fromClient=emailDigest&pageNum=4
Currently, when that link is clicked on, it opens a browser (duh) and then the redirect.jsp page parses that link to get the client name, in this case emailDigest. It then calls window.open('mysite.com/index.jsp?pageNum=4','emailDigest'). This creates a new window with the name emailDigest unless a window/tab with that name already exists, in which case it merely updates the URL in that window with the new one.
I want to either be able to close the original window (the one with the redirect.jsp address) or not have to open that initial window at all.
NOTE
As there are many different clients that want to be able to do this, I cannot guarantee that they will be creating the link with HTML so the target attribute is not the answer.
The correct answer is "No, it cannot be done". If you do not open a window with Javascript then you cannot close it with Javascript. I would always have to create at least 2 windows, which is not what we wanted.
I think you're looking for window.location instead of window.open.
Please use window.location.replace("http://mysite.com/index.jsp?page=awesome");
Reason :
replace(url):Replace the current document with the one at the provided
URL. The difference from the assign() method is that after using
replace() the current page will not be saved in session history,
meaning the user won't be able to use the Back button to navigate to
it.
As haynar says above, why do you open a window and not either:
<!-- content contains the refresh delay in seconds and the target url -->
<meta http-equiv="Refresh" content="1; URL="http://mysite.com/index.jsp?page=awesome">
or use javascript to do the same:
window.location.href = "http://mysite.com/index.jsp?page=awesome";
either works fine and will leave you with one window open.
To get the named window use a targeted link:
Mysite.com
This will automatically set the name property of the opened window.
I have a page with several links that open a separate window with varying content. My goal is to open a window for each and every such link using JavaScript. My problem is as follows:
let's assume:
- i have two links on the page, lnkDoWorkOne and lnkDoWorkTwo
- lnkDoWorkOne opens a window with url = WorkOne.aspx which in turn does some work upon loading
- lnkDoWorkTwo opens a window with url = WorkTwo.aspx which also does some work
In my present solution when I click lnkDoWorkOne then a new window opens with WorkOne.aspx and works just fine. Then when I click lnkDoWorkTwo, then there's no new window at all but the contents of the previously opened window are simply replaced by WorkTwo.aspx. I need to have BOTH windows open with WorkOne.aspx and WorkTwo.aspx so that the user can view the contents in parallel.
Does anyone know how to achieve this?
Are you giving the same window name to the both window.open calls? If so, change the name of the window and you should get two separate windows.
window.open('WorkOne.aspx', 'window1');
...
window.open('WorkTwo.aspx', 'window2');
At the moment to get to an external link from our intranet, we have to copy the link, and paste the link into a new window. Is there any way we can achieve this in a single function in javascript?
Thanks
UPDATE:
When users login from outside the network, urls are changed. This is what we need to code for. I think I the following is applied twice, from server side and client side (this code is not editable):
s=s.replace(/location.assign\(([^;]*)\)/g,"location.assign(alter_url($1))")
s=s.replace(/location.replace\(([^;]*)\)/g,"location.replace(alter_url($1))")
if(s.match(/location\s*=\s*([^;]*)(;?)/)!=null&&s.match(/\.open\(.+,.+,.*location\s*=.+\)/)==null)
s=s.replace(/location\s*=\s*([^;]*)(;?)/g,"location=alter_url($1)$2")
s=s.replace(/location\.href\s*=\s*([^;]*)(;?)/g,"location.href=alter_url($1)$2")
s=s.replace(/window\.open\(([^,]*)(,.*)?\)/g,"window.open(alter_url($1)$2)")
s=s.replace(/\.src\s*=\s*([^;]*)(;?)/g,".src=alter_url($1)$2")
s=s.replace(/\.action\s*=\s*([^;]*)(;?)/g,".action=alter_url($1)$2")
s=s.replace(/\.innerHTML\s*=\s*([^;]*)(;?)/g,".innerHTML=alter_html($1)$2")
s=s.replace(/\.outerHTML\s*=\s*([^;]*)(;?)/g,".outerHTML=alter_html($1)$2")
Actually, the more I look at this, the more unrealistic it's becoming..
Right-clicking and choosing "Open in new window" doesn't work? Because if not, I'm not seeing a Javascript workaround working either. But:
You can open a new window with a specific URL (e.g., link) in Javascript easily enough:
window.open("http://stackoverflow.com");
And there are ways of getting the text that's selected in a page, to feed into that. All of which can be wrapped up into a bookmarklet so that the action becomes "select the text, click a link on the bookmark toolbar".
But if "Open in new window" doesn't work, I wouldn't expect that to work either.
You can use the window.open to open the links on a new window. In fact, you could use a bookmarklet to set the target to _blank on every link on the site, in case you can't access the application source code.
BTW, if you hold the Shift key when opening the link it will open on a new window.