Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在window.open方法中传递参数?_Javascript_Jquery_Asp.net_Html_Asp.net Mvc - Fatal编程技术网

Javascript 如何在window.open方法中传递参数?

Javascript 如何在window.open方法中传递参数?,javascript,jquery,asp.net,html,asp.net-mvc,Javascript,Jquery,Asp.net,Html,Asp.net Mvc,我在JavaScript中有以下方法: var string1 = "testing"; var date = "10/10/2012"; var win = window.open(BuildUrl(("report", "report"), "myreports", "toolbar=0,statusbar=0,scrollbars=1,resizable=1,location=0"); function BuildUrl(controllerName, act

我在JavaScript中有以下方法:

var string1 = "testing";
var date = "10/10/2012";

var win = window.open(BuildUrl(("report", "report"), "myreports",  
           "toolbar=0,statusbar=0,scrollbars=1,resizable=1,location=0");

function BuildUrl(controllerName, actionName) {        
    var TimeStamp = Number(new Date()); 
    var win = window.location;
    return win.protocol + "//" + win.host + "/" + controllerName + "/" + actionName + '?_=' + TimeStamp ;  
}
C控制器中的方法如下所示:

public ActionResult report()
{               
    return View();
}

现在,我需要将URL访问C方法时的名称和日期等参数传递给C方法。如何执行此操作?

以以下格式将参数附加到URL:

<url>?param1=value1&param2=value...

请阅读ASP.NET MVC中的

以以下格式将参数附加到URL:

<url>?param1=value1&param2=value...

阅读ASP.NET MVC中的内容

我发现了一种更好的方法,可以将参数传递到弹出窗口,甚至从中检索参数:

在主页中:

在弹出窗口中:

就这样

这非常方便,因为:

您不必在弹出窗口的URL中设置参数。 没有可定义的表格 可以使用不受限制的参数甚至对象。 双向:您可以传递参数,如果需要,还可以检索新参数。 非常容易实现。
玩得开心

我找到了一种更好的方法将参数传递到弹出窗口,甚至从中检索参数:

在主页中:

在弹出窗口中:

就这样

这非常方便,因为:

您不必在弹出窗口的URL中设置参数。 没有可定义的表格 可以使用不受限制的参数甚至对象。 双向:您可以传递参数,如果需要,还可以检索新参数。 非常容易实现。
玩得开心

如何在c函数中接收它们?如果我们也有两个以上的参数,我们必须使用&作为分隔符传递,对吗?是的,从开始?使用&.添加参数。但如果我这样做,其抛出语法错误,我们需要将param1,param2声明为var变量吗?很难说没有看到您的代码,请用代码更新问题。如何在c函数中接收它们?如果我们也有两个以上的参数,我们必须使用&.作为分隔符传递,对吗?是的,从开始?使用&添加参数,但如果我这样做,抛出语法错误,我们需要将param1,param2声明为var变量吗?如果没有看到您的代码,很难说,请使用代码更新问题。您还可以通过设置window.open返回的窗口对象中的值来传递数据。您还可以通过设置window.open返回的窗口对象中的值来传递数据。
public ActionResult Report(string name, DateTime date)
{
  ...
}
var popupwindow;
var sharedObject = {};

function openPopupWindow()
{
   // Define the datas you want to pass
   sharedObject.var1 = 
   sharedObject.var2 = 
   ...

   // Open the popup window
   window.open(URL_OF_POPUP_WINDOW, NAME_OF_POPUP_WINDOW, POPUP_WINDOW_STYLE_PROPERTIES);
   if (window.focus) { popupwindow.focus(); }
}

function closePopupWindow()
{
    popupwindow.close();

    // Retrieve the datas from the popup window
    = sharedObject.var1;
    = sharedObject.var2;
    ...
}
var sharedObject = window.opener.sharedObject;

// function you have to to call to close the popup window
function myclose()
{
    //Define the parameters you want to pass to the main calling window
    sharedObject.var1 = 
    sharedObject.var2 = 
    ...
    window.opener.closePopupWindow();
}