开发者

Passing a parameter to a popup in javascript [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

JavaScript query string

...Riight. I found the answer to my problem. I'd forgot to add '' around some jsp scriplet tags in my popup window code. Because of this values that should've been strings weren't handled properly.

I'll flag this question for moderator attention. The only thing one can learn from this question is to pay attention when using jsp scriptlets.

I want to open a popup from my .js code using window.open(). I have a couple of parameters that I need to pass to this popup. I'm surprised it's not as simple as I would've thought, I've tried searching for answers but all I found were solutions that were quite complicated - I hope there's a simple answer.

There's a multitude of ways I've tried doing this, but this is how I think it should work..

window.open('../common/MapPopup.jsp?current='+currentPosition+'&areas='+sAreas, 'mywindow', 'width=600,height=450,scrollbars=yes');

I'm at a total loss. Could it be that window.open just doesn't work in this situation?

edit: Currently my page behaves like this. The user presses a form button, which launches a query into our database. From this data a DataTables table is created. As the DataTable is being initialised, so is a piece of jQuery code. I'm using jQuery to open a popup when the user clicks on a row in the DataTables table.

renderReport: function(response){
                $('#requestDataContainer').html(response);
                oTable = $('#dataTable').dataTable({
                    "bPaginate": true,
                    --snip-- //DataTables init
                });

                var sProcedures = new Array();
                var sAreas = new Array();
                var sCurrentPosition = null;

                $('#dataTable tr').click(function(){
                    var sCurrentPosition = oTable.fnGetData(this,9);
                    if(sCurrentPosition!=null){
                        $('#dataTable').find('tr').each(function(){
                            var foo = oTable.fnGetData(this);
                            if(foo!=null){
                                if(foo[8]!='null')
                                    sAreas.push(foo[8]);
                                if(foo[7]!='null')
                                    sProcedures.push(foo[7]);
                            }
                        });
   开发者_如何学运维                 }


                    window.open('../common/reportMapPopup.jsp?procedures='+sProcedures+'&areas='+sAreas+'&current='+sCurrentPosition, 'reportMap', 'width=600,height=450,scrollbars=yes');
                });
          },

I have to admit, I'm quite newbish when it comes to webcode. I'm kind of learning on the go, so the terminology might be new to me and I could be doing things in a really silly way. It could be that I found the answer when I was looking for it on the web, but just didn't realise it.


If the query string in your url gets passed to the window you should be able to access those parameters from the window using JS using the location object(http://www.w3schools.com/jsref/obj_location.asp)

If you have access to the actual page - can you not retieve the params using jsp?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜