Internet Explorer 8, 9 window.open issue

2019-08-16 15:14发布

问题:

when opening the code blow in IE 8 and 9 it opens only the http://translate.google.com/ without the languages codes and the sentences. it works fine in Chrome and Firefox.

function DoTransGg(){
window.open('http://translate.google.com/#en|de|I want to travel with him.','_blank')
}
<input type='button' value='Google Translate' onclick='DoTransGg()'>

回答1:

IE exhibits this behaviour only when used on localhost. With a remote webserver, it functions correctly, and includes the hash when executing window.open(url...#...).



回答2:

I have created a jsFiddle that works with your provided code, with a small change. I included the use of encodeURIComponent() on the sentence to ensure your URL is formed correctly.