最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How do I pass a variable using window.open()? - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Oct 13, 2010 at 20:06 MrMMrM 22.1k31 gold badges116 silver badges142 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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)

  1. 暂无评论