简体   繁体   English

如何在jquery或javascript中使用window.location.replace

[英]How to use window.location.replace in jquery or javascript

I have a website for which I have implemented livechat, when user clicks on livechat link it opens a new window that is fine. 我有一个已实施了实时聊天的网站,当用户单击实时聊天链接时,它将打开一个新窗口。 I want to do is when no operator is online then it should not open a new window when livechat link clicked instead it should redirect to the contact us page of the website in the same window in the currently opened tab, Is it possible? 我想做的是,当没有操作员在线时,单击livechat链接时不应打开新窗口,而应在当前打开的选项卡的同一窗口中重定向到网站的“与我们联系”页面,是否可以? I do not know how is it possible, what I have tried is this , it redirects to this page but opens in a new window. 我不知道怎么可能,我试过的是this,它将重定向到此页面,但在新窗口中打开。

window.location.replace('http://mywebsite.com/index.php?route=information/contact');

The problem is somewhere in the code around that. 问题出在代码周围。 You need to call that code in the old window. 您需要在旧窗口中调用该代码。

If you want to call it in the chat window, try: 如果要在聊天窗口中调用它,请尝试:

window.opener.location.replace('http://mywebsite.com/index.php?route=information/contact');
window.close()

改用href属性:

window.location.href = 'http://mywebsite.com/index.php?route=information/contact';

You can use simple javascript code like this: window.location.href = "SOME URL" it will do the same think. 您可以使用以下简单的javascript代码:window.location.href =“ SOME URL”,它会做同样的事情。 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM