Skip to content Skip to sidebar Skip to footer

Error When Using Js In Href Ie 11

I have a link: someText it works fine everywhere except ie(i try i

Solution 1:

If you use a javascript URI scheme in a HTML href attribute, this is different to using an onclick event handler.

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

To avoid this (without refactoring your code to not do things this way), you can end your href with the javascript operator void, which tells your javascript to return nothing, at all (well, undefined).

Then IE will stay on the current page.

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

...and you probably don't want the target="_blank" since you're telling a new window to run your JavaScript code, and your function is not available in that window.

Solution 2:

I would do this instead:

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

It will open a new tab as you intended, and it works in chrome, firefox and IE.

Post a Comment for "Error When Using Js In Href Ie 11"