简体   繁体   English

Window.location-PHP中的JavaScript

[英]Window.location - javascript in php

I've create in my php programme a piece of code: 我在php程序中创建了一段代码:

$dest = 'https://www.google.com';

$stay = 'currenturl';
          echo '<pre>'; 
          echo "<script language=\"javascript\">";
          echo "    window.location = '". $stay."';";
          echo "    var win = null;";
          echo "    LeftPosition = (screen.width) ? (screen.width-995)/2 : 0;";
          echo "    TopPosition = (screen.height) ? (screen.height-640)/2 : 0;";
          echo "    settings = 'height=500,width=600,top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=yes,status=yes';";
          echo "    win = window.open('" . $dest . "','network',settings);";
          echo "</script>"; 
          echo '</pre>';    
          exit; 

If I run this code it will open my pop up window, which is google, and refresh (because it's the only idea I've got which allow me to stay on the same page - otherwise it goes blank...) current page. 如果我运行此代码,它将打开我的弹出窗口,即google,并刷新(因为这是我唯一拥有的让我保持在同一页面上的想法,否则它将变成空白...)当前页面。 I want to avoid refreshing and stay on the same page. 我想避免刷新并停留在同一页面上。

Do you know how to change this "window.location" to achieved it? 您知道如何更改此“ window.location”来实现吗?

mate, you should not use php code to open a new window by injecting js script, that's why you are going to another page as the php code ouput new content to the current page, you should have all your logic about new window in a JavaScript function. 伙伴,您不应通过注入js脚本使用php代码打开新窗口,这就是为什么要转到另一页,因为php代码会将新内容输出到当前页面,因此您应该在JavaScript中拥有有关新窗口的所有逻辑功能。 then you should stay on the same page 那你应该留在同一页上

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

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