开发者

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

开发者 https://www.devze.com 2023-01-20 01:37 出处:网络
I would like to add some variables when my window.open function fires. Example:开发者_StackOverflow社区

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

Example:开发者_StackOverflow社区

<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"];


pass the value as a query string

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


Pass it in the query string or fragment, and parse it on the other page.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消