Seems like there are a few issues that need addressing.
Guidance on Opening Links in a New Browser Tab
It's important to consider the user's preferences when opening links in a web browser. Altering the default behavior can be ethically questionable. It is best to allow users to choose how they want to open a link themselves.
However, if you absolutely need to force a link to open in a new browser window, the traditional method of using the target="_blank"
attribute no longer works. Most modern browsers will open the link in a new tab instead. To achieve this, you can use the window.open()
function, but use it sparingly and considerately.
If you do decide to implement this function, you can do so in a cleaner way by adding a class .new-window
to the link, without resorting to intrusive onclick
attributes:
(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>
▲ Try it on codepen.io (snippets on SO are sandboxed)
It's important to note that using window.open
should not trigger popup blockers if the action is initiated by the user. However, attempting to open a new window without direct user interaction, such as through a timer or keyboard event, may result in the popup being blocked.
Dealing with Unsupported Media Types
Contrary to popular belief, there is no native support for Windows Media Player in web environments. Instead, consider using the video
tag for embedding videos on your website. If you are unable to upload training videos to YouTube, convert them to formats like webm
or h.264
and use the video
tag as follows:
<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>