In firefox browser, Window.open strangely displaying [object Window] after clicking

Viewed 836

I have set anchor link so that on click it will open link into new window.

I have used below code to open new link into new window.

<a href="javascript:window.open('https://www.remax.fi/fi/kiinteistonvalitys/tietosuojaseloste/', 'newwindow', 'fullscreen=1')">"tietosuojaselosteeseen"</a>

url : https://www.remax.fi/fi/

On above url page, in bottom there been contact form on which I have set anchor link in text tietosuojaselosteeseen.

In chrome browser it working properly but In firefox browser it display error page which show [object Window] text.

Please find screenshot for further clarification.

I have tried much to find solution of this problem but not able to figure out this.

Please help me if any one have idea regarding it.

enter image description here enter image description here

2 Answers

When you put the Javascript in the href, the page also navigates to whatever the Javascript returns. In this case window.open returns a copy of the window object, which can't be navigated to.

You can solve this by moving the Javascript to onclick and having a href="#", or you can add a ;return false after the window.open, or put void() around the window.open,

I think you can just use onlick event for this. You can modify your code like this

<a href="javascript:;" onclick="window.open('https://www.remax.fi/fi/kiinteistonvalitys/tietosuojaseloste/', 'newwindow', 'fullscreen=1');return false;">"tietosuojaselosteeseen"</a>

Here, on href it will execute like javascript:void(0); and we call the window.open on click event. Also return false if there are other events triggers with it.

Related