Use window.open():
<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
Share Page
</a>
This will create a link titled Share Page which opens the current url in a new window with a height of 570 and width of 520.
Just use window.open() function? The third parameter lets you specify window size.
Example
var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";
var URL = "https://www.linkedin.com/cws/share?mini=true&url=" + location.href;
var win = window.open(URL, "_blank", strWindowFeatures);
That will open a new window, not tab (with JavaScript, but quite laconically):
<a href="print.html"
onclick="window.open('print.html',
'newwindow',
'width=300,height=250');
return false;"
>Print</a>
With pure HTML you can't influence this - every modern browser (= the user) has complete control over this behavior because it has been misused a lot in the past...
HTML option
You can open a new window (HTML4) or a new browsing context (HTML5). Browsing context in modern browsers is mostly "new tab" instead of "new window". You have no influence on that, and you can't "force" modern browsers to open a new window.
In order to do this, use the anchor element's attribute target[1]. The value you are looking for is _blank[2].
<a href="www.example.com/example.html" target="_blank">link text</a>
JavaScript option
Forcing a new window is possible via javascript - see Ievgen's excellent answer below for a javascript solution.
(!) However, be aware, that opening windows via javascript (if not done in the onclick event from an anchor element) are subject to getting blocked by popup blockers!
[1] This attribute dates back to the times when browsers did not have tabs and using framesets was state of the art. In the meantime, the functionality of this attribute has slightly changed (see MDN Docu)
[2] There are some other values which do not make much sense anymore (because they were designed with framesets in mind) like _parent, _self or _top.
WMV is not a format supported by the HTML5 video player in browsers. You should try converting your video to a support format like h264 (mpeg) or webm.
On top of that, you may want to create an actual player.html page that you can load in the newly opened window so that you're able to configure settings like autoplay, which player controls are visible, etc. This could also give you the opportunity to allow video format fallbacks in case one of the encoded video formats is not supports, another will be chosen.
You could avoid having to create separate player pages for each video by passing a query string parameter in the URL that tells the player page which video to load.
It seems you have a few issues here.
Forcing browser to open a link in a new window
It's important to note, that messing with expected browser's behaviour is morally wrong. You should always let user decide how he wants to open a particular link.
However, if you really need to know, here's the answer. In the past, attribute target="_blank" used to open links (and forms) in a new window, but it doesn't anymore. Since browsers got more friendly, it'll just open the result in a new tab.
If you want to force browser to open a link in a new window, you need to use window.open() function. However, I beg you, do not throw it around too much. If you absolutely need to implement this function, at least make it a little bit less evil, like the following (so you're only adding a class .new-window without ugly onclick-s or anything like that:
(function(){
var links = document.querySelectorAll('a.new-window');
for (var i = 0; i < links.length; ++i) {
links[i].addEventListener('click', function(e) {
e.preventDefault();
// Note that it'll not work inside SO snippets preview because of the sandbox!
// Try on http://codepen.io/xerif/pen/JWggoJ
window.open(this.getAttribute('href'), '', [
'width=' + screen.availWidth,
'height=' + screen.availHeight
]);
// Also note that array will be converted to proper string automagically
// I used array for readability
});
}
})();
<a href="http://stackoverflow.com/q/43333255">Normal link</a> /
<a href="http://stackoverflow.com/q/43333255" target="_blank">Open in a new tab (probably)</a> /
<a href="http://stackoverflow.com/q/43333255" class="new-window">Open in a new window</a>
Run code snippetEdit code snippet Hide Results Copy to answer Expand
▲ try it on codepen.io (snippets on SO are sandboxed)
It's worth noting, that window.open should not be blocked by popup blockers as long as window originated from user's action. However, if you try to open a window without user initiating that action — silently, by something like a timer or keyboard event — it will be blocked.
Unsupported media type
As other people have hinted, there's no such thing as Windows Media Player in web environment. It just doesn't exist. Forget you know it. Do it.
Instead, you may want to use video tag. As I understand, FBI prohibits you from putting training videos on YouTube, so you'll need to convert them to more appropriate format, like webm or h.264. Then:
<video src="\\OC2-RMGFS\Public\Safety\runhidefight-eng.mp4" poster="./images/Youtube.png">
We can't play this video in your browser. Can you <a href="\\OC2-RMGFS\Public\Safety\runhidefight-eng.mp4" download>download it</a>?
</video>
Run code snippetEdit code snippet Hide Results Copy to answer Expand
<a href="#" onClick="window.open('http://www.yahoo.com', '_blank')">test</a>
Easy as that.
Or without JS
<a href="http://yahoo.com" target="_blank">test</a>
In order to open a link in a new window, add Javascript command
onclick="window.open('text-link.htm', 'name','width=600,height=400') inside the <a> tag:
<a href="../html-link.htm" target="popup" onclick="window.open('../html-link.htm','name','width=600,height=400')">Open page in new window</a>
Opens a new window with the url you supplied :)
Use with AI<button class="button" onClick="window.open('http://www.example.com');">
<span class="icon">Open</span>
</button>
I couldn't get your method to work @Damien-at-SF...
So I resorted to my old knowledge.
By encasing the input type="button" within a hyperlink element, you can simply declare the target property as so:
Use with AI<a href="http://www.site.org" target="_blank">
<input type="button" class="button" value="Open" />
</a>
The 'target="_blank"' is the property which makes the browser open the link within a new tab. This attribute has other properties, See: http://www.w3schools.com/tags/att_a_target.asp for further details.
Since the 'value=""' attribute on buttons will write the contained string to the button, a span is not necessary.
Instead of writing:
Use with AI<element></element>
for most HTML elements you can simply close them with a trailing slash, like so:
Use with AI<element />
Oh, and finally... a 'button' element has a refresh trigger within it, so I use an 'input type[button]' to avoid triggering the form.
Good Luck Programmers.
Due to StackOverflow's policy I had to change the domain in the example: https://meta.stackexchange.com/questions/208963/why-are-certain-example-urls-like-http-site-com-and-http-mysite-com-blocke
Set the target attribute to _blank.
You have no control over what sort of new "window" the browser will open it in. It might be an actual window, it might be a tab, it might be overridden and forced to the same window.
It is, however, a bad idea, so don't do it, really, please don't.
you no need to write such long javascript to do with your requirement. Just set target attribute to _blank in your anchir tag itself. whenever a user click on that link it will open in new tab. sample tag is as follow
<a href="www.google.com" target="_blank">Google</a>
Hope this helps you
NOTE: For Security reason
<a href="http://www.starfall.com/" target="_blank">Starfall</a>
Whether it opens in a tab or another window though is up to how a user has configured her browser.
Simplest way is to add a target tag.
<a href="http://www.starfall.com/" target="Starfall">Starfall</a>
Use a different value for the target attribute for each link if you want them to open in different tabs, the same value for the target attribute if you want them to replace the other ones.
You have to set target="_blank" attribute on your link
For example :
<a href="http://www.zzz.com\?tp=win95" target="_blank"/>
No, that has to be specified by the link itself:
<a href="http://www.zzz.com\?tp=win95" target="_blank"/>
or by JavaScript:
window.open(URL,name,specs,replace);
Here's a link to the JS method: http://www.w3schools.com/jsref/met_win_open.asp
This is how to open a link in a new window.
<a href="myLink"
target="popup"
onclick="window.open('myLink','popup','width=600,height=600'); return false;">
Open Link in Popup
</a>
Always remember the sometimes that user configures their browsers to block all new tabs and windows (at least this is what I do), to avoid annoying advertisements and click baits links.
Any method which opens a new browser context without specifying the dimensions will use either a tab or a window according to the user's preferences.
In general, it isn't a good idea to try to bypass that preference. If a user decides they want a tab in a new window, they can always tear it off into one.
That said, if you specify dimensions, it will trigger a new window if the browser supports that at all (most mobile devices, for example, don't support windows at all).
addEventListener("click", event => {
const target = event.target;
if (!target.classList.contains("force-window")) {
return;
}
const url = target.href;
const width = window.innerWidth;
const height = window.innerHeight;
const features = `width=${width},height=${height}`;
window.open(url, "_blank", features);
event.preventDefault();
});
<a href="myLink" target="_blank" rel="noreferrer" class="force-window">myText</a>
Unfortunately, this will produce a window missing most of the expected features. See the window.open documentation to add them back, but note that (in Chrome at least) adding the menubar back will cause the height and width to be ignored and put things back in a new tab.
Author controlled new windows are a pain and are almost always best avoided. I wouldn't touch them unless I needed to do something like pop out some content (like a chat or music player) in a small window that could remain on screen while the user navigated the site … and even then I'd generally lean towards writing a SPA instead.
It's far better to attach this to the hyperlink unobtrusively, similar to:
HTML
<a href="mypopup.htm" id="popup">This will open in a new window</a>
JavaScript
window.onload = function() {
document.getElementById("popup").onclick = function(){
return !window.open(this.href, "pop", "width=200,height=600");
}
}
The benefit of this approach is that you only have to specify the hyperlink in your HTML, and if JavaScript is disabled or produces an error for some reason then it will fallback to just using a standard hyperlink.
Creating a New Window with JavaScript (includes window size)
http://www.fontstuff.com/frontpage/fptut06.htm
You can like:
window.open('url', 'window name', 'window settings')
jQuery:
$('a#link_id').click(function(){
window.open('url', 'window name', 'window settings');
return false;
});
You could also set the target to _blank actually.
Here's how to force the target inside a click handler:
$('a#link_id').click(function() {
$(this).attr('target', '_blank');
});
In javascript:
window.open("url");
Or adding the attr:
document.getElementById("theLink").setAttribute("target", "_blank");
With the following html
<a id="theLink" href="url">
If you cannot modify any part the a tag, you can use jquery.
The following script will try to open all links on a different tab/window:
$("a").on("click",function(){
event.preventDefault();
window.open($(this).attr('href'),'_blank');
});
NOTE:
Make sure you read this answer