简体   繁体   English

未在window.open中打开网址

[英]Not opening the url in window.open

I have a link in the page.On clicking the link the pop up should render with required url.I have the window.open code as follows 我在页面上有一个链接。单击链接后,弹出窗口应使用所需的网址呈现。我有window.open代码,如下所示

<a href="javascript:;" onclick="window.open('/action.do?name=aravind&age=19&url=http://astrik.com/click?id=613*B&offerValue=2.9','chatWindow','menubar=1, scrollbars=yes, resizable=yes, width=600,height=450');return false;">Click here</a>

on clicking above link the popup is opening with url upto http://astrik.com/click?id=613 *B and offerValue is not showing up in the url of pop up.I need the offerValue to be shown in the url.Any reason for not showing up the offerValue. 在单击上面的链接时,弹出窗口的URL会打开,直到http://astrik.com/click?id=613 * B,并且offerValue没有显示在弹出的URL中。我需要在URL中显示offerValue。不显示offerValue的任何原因。

Try the following: 请尝试以下操作:

<a href="javascript:;" onclick="window.open('/action.do?name=aravind&age=19&url=http://astrik.com/click?id=613*B%26offerValue=2.9','chatWindow','menubar=1, scrollbars=yes, resizable=yes, width=600,height=450');return false;">Click here</a>

You must URL encode your parameters for the "url" value, otherwise they will get appended to the original URL. 您必须参数进行URL编码以获取“ url”值,否则它们将被附加到原始URL。

You should escape the data parts in url's before using it. 在使用之前,您应该转义url中的数据部分。 In this case the data part url is bugged by the ampersand(&) in the url. 在这种情况下,数据部分的URL被URL中的“&”号所干扰。

var url = encodeURIComponent('http://astrik.com/click?id=613*B&offerValue=2.9');


<a href="javascript:void(0);" onclick="window.open('/action.do?name=aravind&age=19&url=' + url,'chatWindow','menubar=1, scrollbars=yes, resizable=yes, width=600,height=450');return false;">Click here</a>

(or just replace the ampersand, not sure now) (或者只是更换“&”号,现在不确定)

The provided URL contains a ? 提供的URL包含一个? that indicates the start of an argument list. 指示参数列表的开始。 Each argument is separated by an & . 每个参数由&分隔。 Thus, for the parser the provided argument list look like this: 因此,对于解析器,提供的参数列表如下所示:

name=aravind , age=19 , url=http://astrik.com/click?id=613*B and offerValue=2.9 . name=aravindage=19url=http://astrik.com/click?id=613*BofferValue=2.9 They all belong to the request to /action.do . 它们都属于对/action.do的请求。

You need to escape the last amp with its URL escape code %26 like this: 您需要使用其URL转义代码%26对最后一个放大器进行转义,如下所示:

/action.do?name=aravind&age=19&url=http://astrik.com/click?id=613*B%26offerValue=2.9

to "bind" the last argument to the astrik URL. 将最后一个参数“绑定”到astrik URL。 Maybe it is also required to escape the second ? 也许还需要逃脱第二个? with %3F . %3F

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

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