IE javascript 位置,window.open

发布于 2024-11-02 09:26:16 字数 980 浏览 3 评论 0原文

我有一个小问题。由于某些奇怪的原因,任何通过 javascript 更改 url 的尝试(无论是 window.open、window.location、window.location.href 等)都不会移动到所需的页面,而是将其添加到 url 的末尾。无论 IE 版本如何,从 6-8

例如

http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639

结束于

http://localhost/blabla/produkt/philips-fc-861501-animal-care/added-by-javascript

我不知道为什么会发生这种情况...

在此页面上

http://localhost/blabla/objednat-tovar?step=deal-detail

它按预期工作。

感谢任何帮助...

编辑:

一些代码。

我在

http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639

// code
<a href="javascript:aaa(\'new_location\');" title="test">test</a>

function aaa(where) {
     window.location = where;
}

Ends in

http://localhost/blabla/produkt/philips-fc-861501-animal-care/new_location

同样的事情发生在 window.location.href、window.open 并且仅在 IE 中

I have a small problem. For some weird reason any attempt to change url via javascript, be it window.open, window.location, window.location.href, etc. doesnt move to the desired page, but adds it to end of the url. It doesnt even matter what IE version, from 6-8

E.g.

http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639

ends in

http://localhost/blabla/produkt/philips-fc-861501-animal-care/added-by-javascript

I have no idea why this happens...

On this page

http://localhost/blabla/objednat-tovar?step=deal-detail

it works as intended.

Any help is appreciated...

EDIT:

Some code.

I am on

http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639

// code
<a href="javascript:aaa(\'new_location\');" title="test">test</a>

function aaa(where) {
     window.location = where;
}

Ends in

http://localhost/blabla/produkt/philips-fc-861501-animal-care/new_location

Same thing happens with window.location.href, window.open and only in IEs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

祁梦 2024-11-09 09:26:16

我猜测浏览器会尝试将 位置解析为 URL 并且如果然后它会失败,大概它会做任何它想做的事情(IE 似乎将字符串附加到当前位置)。例如:

window.location = 'about:blank'; // OK, since it's a valid pseudo-url.
window.location = 'foo'; // No effect, since this isn't a URL.
window.location = 'http://example.com/'; // OK, browse to that page.
window.location = 'bar'; // Depends on what the browser wants to do...

I'm guessing that the browser tries to parse the location as a URL and if it fails then, presumably, it does whatever it wants (IE seems to append the string to the current location). For example:

window.location = 'about:blank'; // OK, since it's a valid pseudo-url.
window.location = 'foo'; // No effect, since this isn't a URL.
window.location = 'http://example.com/'; // OK, browse to that page.
window.location = 'bar'; // Depends on what the browser wants to do...
旧伤还要旧人安 2024-11-09 09:26:16

这里不需要 javascript:

<a href="#" onclick="aaa(\'new_location\');" title="test">test</a>

function aaa(where) {
     window.location = where;
}

you don't need javascript: here

<a href="#" onclick="aaa(\'new_location\');" title="test">test</a>

function aaa(where) {
     window.location = where;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文