Javascript window.open weird behavior in Firefox

I have several links that should open in one window or tab. To do this, I gave the window a name such as in this code example:

<a href="#" onClick='window.open("http://somesite.com", "mywindow", "");'>link 1</a>
<a href="#" onClick='window.open("http://someothersite.com", "mywindow", "");'>link 2</a>

This works fine in Internet Explorer, but firefox always opens a new tab / window. Any ideas?

+3
source share
4 answers

The window.open () function in Javascript is specifically designed to open a new window, see w3schools documentation . Actually, it sounds like IE handles things in a non-standard way (which is not surprising).

If you want to move an existing location to a new page using Javascript, you should look at location.replace () .

, Firefox IE. , Firefox , W3C .

+8

, W3Schools, gabriel1836, .

, mozilla CONTRADITCS .

MDC/DOM/Window.open

var WindowObjectReference = window.open(strUrl, 
              strWindowName [, strWindowFeatures]); 

strWindowName , , strUrl . - strWindowFeatures . strUrl . window.open(), _blank strWindowName.

, , , .

, mozilla , , , - :)

, A-Href .

  <a href="http://google.com"  
     onclick="window.open( this.href, 'windowName' ); return false" >
     Text
  </a>

.

"" , , , href "#" .

"#" - , - , - , onclick

FALSE on-click, ( )

, , unintrusive javascript :

 <a href="google.com" rel="external" >Text</a>

 <script type="text/javascript">
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){ 
            window.open(this.href, 'newWindowName' ); 
            return false; 
        });
 }); 
 </script>
+14

By default, FF uses a new tab if parameter sizes are omitted in window.open parameters. You need to add dimensions for the new browser window.

Try the following:

<a href="#" onClick='window.open("http://somesite.com", "mywindow", "width=700", "height=500");'>link 1</a>
+6
source

Why don't you just use plain HTML like

<a href="http://www.google.com" target="my_window_tab_frame_or_iframe">Link</a>

instead of using javascript?

+2
source

Source: https://habr.com/ru/post/1699213/


All Articles