javascript:使用window.open()发送自定义参数但不起作用 [英] javascript : sending custom parameters with window.open() but its not working

查看:452
本文介绍了javascript:使用window.open()发送自定义参数但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
<script>
function open_win()
{
    window.open("http://localhost:8080/login","mywindow")
}
</script>
</head>
<body>

<input type="button" value="Open Window" onclick="open_win()">

</body>
</html>

您好,

点击一下按钮,我打开新网站(我的网站)
我有两个文本字段(一个文本字段和另一个密码字段),我试图将此值发送到另一个打开的窗口。

On click of a button , i am opening a new website (My web site ) I have two text fields ( One Text Field and another Password Field) , i am trying to send this values to the other opened window .

但它没有按我的意愿工作。

But its not working as I want.

我尝试了以下方式

1.  window.open("http://localhost:8080/login?cid='username'&pwd='password'","mywindow")

2.  window.open("http://localhost:8080/login","mywindow")
    mywindow.getElementById('cid').value='MyUsername'
    mywindow.getElementById('pwd').value='mypassword'

如果有可能,有人可以帮助我吗?

Could anybody please help me if this is possible or not ??

对于不完整的详细信息感到抱歉,这是一个Post请求。

Sorry for the incomplete details , its a Post request .

推荐答案

如果你想传递POST变量,你必须使用HTML表格:

if you want to pass POST variables, you have to use a HTML Form:

<form action="http://localhost:8080/login" method="POST" target="_blank">
    <input type="text" name="cid" />
    <input type="password" name="pwd" />
    <input type="submit" value="open" />
</form>

或:

如果你想在URL中传递GET变量,写下它们不带单引号:

if you want to pass GET variables in an URL, write them without single-quotes:

http://yourdomain.com/login?cid=username&pwd=password

这里是如何用javascrpt变量创建上面的字符串:

here's how to create the string above with javascrpt variables:

myu = document.getElementById('cid').value;
myp = document.getElementById('pwd').value;
window.open("http://localhost:8080/login?cid="+ myu +"&pwd="+ myp ,"MyTargetWindowName");

在包含该网址的文档中,您必须阅读GET参数。如果是在PHP中,请使用:

in the document with that url, you have to read the GET parameters. if it's in php, use:

$_GET['username']

要注意:以这种方式传输密码是一个很大的安全漏洞!

be aware: to transmit passwords that way is a big security leak!

这篇关于javascript:使用window.open()发送自定义参数但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆