简体   繁体   中英

How do I pass a variable using window.open()?

I would like to add some variables when my window.open function fires.

Example:

<a href="javascript:void(window.open('Details.aspx', 'Title'))"><%# Eval("Id").ToString) %></a>

I would like to pass the id number to the Details.aspx page. How do I do that?

Pass it on the query string:

<a href="javascript:void(window.open('Details.aspx?id=<%# Eval("Id").ToString) %>', 'Title'))"><%# Eval("Id").ToString) %></a>

In Details.aspx you will be able to get it:

var id = Request.QueryString["id"];

将值作为查询字符串传递

<a href="javascript:void(window.open('Details.aspx?id=<%# Eval("Id").ToString) %>', 'Title'))"><%# Eval("Id").ToString) %></a>

将其传递到查询字符串或片段中,然后在另一页上进行解析。

You can reference variables in the parent page from the child page via window.opener . Your parent page would have script something like this:

var detailsId = 0;
function openDetails(id)
{
    detailsId = id;
    window.open('Details.aspx', 'Title');
}

and HTML something like this:

<a href="javascript:void(openDetails('<%# Eval("Id").ToString) %>'))">
    <%# Eval("Id").ToString) %></a>

And your child page could get the id in script like this:

var id = window.opener.detailsId;

enjoy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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