1

I am using the following code to open a new window from my Jquery code:

window.open("/mypage", "mywindow","status=0,toolbar=0, height=500, width=500");

I just wonder if there is a way to add body classes to the new window in the resulting page so I can add some bespoke styling.

Andy E
  • 338,112
  • 86
  • 474
  • 445
sisko
  • 9,604
  • 20
  • 67
  • 139

2 Answers2

2

You could pass the page a GET parameter by appending a query string like this

window.open ("/mypage?bodyClass=nameOfCssClass", "mywindow","status=0,toolbar=0, height=500, width=500");

and then use the value of "bodyClass" on your page (mypage) to set the CSS class of its body tag. This is easiest if you are using any server side code for "mypage" but its possible to read the query string with JavaScript as well.

See Read a URL parameter

Community
  • 1
  • 1
Stefan
  • 5,644
  • 4
  • 24
  • 31
2

You can do something like this:

var w = window.open('','','width=200,height=100');
$(w.document).find('html').addClass('opened-as-popup')

DEMO: http://jsfiddle.net/PNNqE/1/

Niels
  • 48,601
  • 4
  • 62
  • 81