Error using js in href ie 11

I have a link:

<a href="javascript:someObject.someFunction();" target="_blank" style="color: rgb(225, 233, 41);">someText</a>

it works fine everywhere except ie (I'm trying ie11) I have this error

This page can’t be displayed. 
Make sure the web address //ieframe.dll/dnserror.htm# is correct.

How can i solve this?

+4
source share
2 answers

If you use the javascript URI in the HTML href attribute, this is different than using the onclick event handler.

In IE, the result of executing this JavaScript will replace the loaded document.

To avoid this (without reorganizing your code so as not to do it this way), you can end your href with a javascript statement voidthat tells your javascript to return nothing (well, undefined).

Then IE will remain on the current page.

<a href="javascript:someObject.someFunction(); void 0" ...

... , , target="_blank", JavaScript, .

+8

:

<a href="#" onclick="event.preventDefault(); someObject.someFunction();" target="_blank" style="color: rgb(225, 233, 41);">someText</a>

, , chrome, firefox IE.

0

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


All Articles