Open a pop up window maximumize to the user's screen configuration - asp.net

What is best way to open a pop up window maximized to the user's screen configuration? I am using C# ASP.NET 3.5 web site project.
Update:
#Anthony - The windows xp task bar covers up some of the browser window. How do I set to maxmmumize and stop at the windows xp task bar?
Update 1:
I used the following the solution to maxumize the pop up window, but it opens the window first then moves it to the upper left corner of the screen. Is there a way just to open the pop up at the 0,0 position?
function openMaxWindow(url) {
var name = "MyWindow";
var features = "status=1,toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0,height=" + screen.availHeight + ",width=" + screen.availWidth;
var newWindow = window.open(url, name, features);
}
Update 2:
Figured it out, I needed to add top=0 and left=0 to the features list.

Use javascript to run
var newWindow = window.open(); newWindow.resizeTo(screen.width, screen.height);
Obviously, you need to use the appropriate parameters to the window.open() statement.
This link also shows how to do it
Edit
newWindow.moveTo(0,0);
newWindow.resizeTo(screen.availWidth, screen.availHeight);

function maximizeWindow() {
window.moveTo(0, 0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
} else if (document.layers||document.getElementById) {
if (top.window.innerHeight < screen.availHeight || top.window.innerWidth < screen.availWidth) {
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}
}

Related

Select a game object and perform actions using GUI.Button (EventTrigger)

I am currently working on a strategy game and I want to preform actions using GUI.Button on game objects. I am using ray cast and mouse click to select the object however when I click on GUI.Button to take out another action the button disappears. I want to use that button to open up another GUI.Box to show some descriptions.
I know why the button is disappearing, it is because I am projecting the ray cast to my button clicks in the update function but how can I avoid this? I also know that I have to use EventTrigger however I am not familiar with javascript event trigger, I searched online but I couldn't find any helpful javascript.
Screenshots:
Here is my script:
#HideInInspector
var isCalled:int = 0;
#HideInInspector
var scWidth:int = 0;
#HideInInspector
var scHeight:int = 0;
function Start () {
scWidth = Screen.width;
scHeight = Screen.height;
}
function Update () {
if (Input.GetMouseButtonDown(0)) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
if (hit.collider.tag == "House") {
isCalled = 1;
} else{
isCalled = 0;
}
}
}
}
function OnGUI(){
if(isCalled==1)
GUI.Button(Rect(scWidth/2,(scHeight/2)+(scHeight/4),120,120), name);
}
}
If I understood you right, the problem is that when you click on button the raycast is fired up before button click and you select different object or no object at all and button disappears or reappears but for another object, what you need to do is check if you clicked on GUI and if yes don't project the raycast that selects the objects. Here is how you are gonna do it.
var selectedUI : GameObject = EventSystem.current.currentSelectedGameObject;
if (Input.GetMouseButtonDown(0) && selectedUI) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
if (hit.collider.tag == "House") {
isCalled = 1;
} else{
isCalled = 0;
}
}
}
I work in C#, so I might have done some syntax errors, but the logic is right.
There is a good trick when using legacy GUI system to avoid raycast when mouse is over GUI elements. Using tooltip to controll if you may cast your ray =)
Something like this (I also don't work with US so may I it needs some work):
var hover : String;
function OnGUI(){
if(GUI.Button (Rect (10,10,100,20), "My Button"));
hover = GUI.tooltip;
function Update () {
if(hover != "") {
// raycast logic
}
}
If you need to avoid raycast when your "popUp" window/panel is shown but you don't want a tooltip on it you may approach using a MouseOverGUI manager too.
It is just a static or singleton holding a boolean that you will set true when your mouse is over some rect that you don't want to cast rays using Rect.Contains(Event.current.mousePosition) and to false whenever it runs out of this rect.
Use this bool with or without tooltip var to allow raycast:
if(!MouseManager.MouseOverGUI) {
// raycast logic
}
Note that creating your rect on each OnGUI cycle will difficult to catch it and control the MouseOveGUI. Also it is a bad practice for performance because OnGUI runs more than once per frame so I'll suggest you to create you rects just once (recalculate it just when needed) and pass it to your GUI elements ;)
I think the easiest way is to create a GameObject(input blocker) which is not visible but have a collider. Place it in between the camera and level objects and deactivate it. When you select a GameObject using Raycast you enable that input blocker GameObject and place it around the area of selected GameObject and GUI. Then you have to ignore the selection if raycast is collided with Input Blocker. When you deselect the Gameobject then you deactivate input blocker
You should also maintain current state of the game for example:
enum State
{
NothingSelected = 0,
GameobjectSelected,
BigMenuOpen
}
State currentState;
So according to state you can define the behavior on mouse click. Like if Full screen menu is Open then raycast does not fire.

Opened multiple popup using window.open().How to make all popup stay at top and also access parent page

I have a scenario where I need to open multiple popup almost 5 . If I use window.open() method , I can open multiple popups but it is not staying on top of parent page all the time. After I open first popup , it shows on top of parent page. then when I access parent page to open second popup , first popup goes behind the parent page. Is there any way I can achieve this functionality.
Any help greatly appreciated
One way is to store the window handles in an array and call the focus method. It works in IE. It will not work in Chrome, details here
FIDDLE
Code below.
var popupWindowsArr = new Array();
function popupClicked() {
var title = "Test -" + popupWindowsArr.length;
var wndID = window.open("http://www.google.com", title, "height=400,width=700");
popupWindowsArr.push(wndID);
for(var i = 0; i < popupWindowsArr.length; i++) {
popupWindowsArr[i].focus();
}
}
EDIT - To bring focus to popups after a postback.
One way is store the names of the opened windows in a hidden field and use it. This will work only if the popup url is in the same domain.
<asp:HiddenField ID="hdnPopupNames" runat="server" />
function popupClicked() {
var popupNames = document.getElementById('<%=hdnPopupNames.ClientID %>').value;
var wndName;
if (popupNames.length > 0) {
var namesArr = popupNames.split("|");
wndName = "Test -" + namesArr.length;
for (var i = 0; i < namesArr.length; i++) {
var wnd = window.open("", namesArr[i]);
wnd.focus();
}
popupNames += "|" + wndName;
}
else {
wndName = "Test - 0" ;
popupNames = wndName;
}
window.open("TestHTMLPage.htm", wndName, "height=400,width=700");
document.getElementById('<%=hdnPopupNames.ClientID %>').value = popupNames;
}

Placing popup window in the middle of the main window

I'm trying to place a popup window (TitleWindow) in the middle of the main application window. how do i set the coordinates of my popup window to be of the main application window?
i tried the localToGlobal function but with no luck, I just can't get the main window x and y.
Thanks in advance,
Uzi.
From the Adobe Docs:
Just call the centerPopUp method in the CreationComplete event of your TitleWindow.
private function handleCreationComplete():void {
// Center the TitleWindow container
// over the control that created it.
PopUpManager.centerPopUp(this);
}
If you're creating the popUp from within a method, you can also try:
public function openWindow(event:MouseEvent):void {
myPopUp = new TextArea();
myPopUp.width= 220;
myPopUp.height= 150;
myPopUp.text = "Hold down the Shift key, and " +
"click in the TextArea to close it.";
myPopUp.addEventListener(MouseEvent.CLICK, closeWindow);
PopUpManager.addPopUp(myPopUp, this, true);
PopUpManager.centerPopUp(myPopUp);
}
Edit: You can also try:
PopUpManager.centerPopUp(Application.application as DisplayObject);
or if the component is directly on your application's main stage
PopUpManager.centerPopUp(this.parent);
Second Edit: If you're using the PopUpManager.addPopUp method to launch your popup, just change the 2nd argument from this to this.parent (or whatever component you like). The 2nd argument tells the PopUpManager what your popup's parent is. Check out the Adobe Live Docs for more info.
PopUpManager.addPopUp(myPopUp, this.parent, true);
myPopUp.x = (Application.application.width - myPopUp.width)/2
myPopUp.y = (Application.application.height - myPopUp.height)/2
#uzi orgad
I think this will be suitable for you, try this
var popup:Object ;
popup = PopUpManager.createPopUp(
FlexGlobals.topLevelApplication as DisplayObject,
popupname, true);
PopUpManager.centerPopUp(popup as mx.core.IFlexDisplayObject);
FlexGlobals.topLevelApplication as DisplayObject points to the main application.So the popup appears at the middle of the application

iframe designMode in firefox

I create iframe with designMode=on.
When I open web site in IE and move mouse cursor on iframe, the mouse cursor get changes into text-cursor (big letter I).
But when I open web site in Firefox, the corsur doesn't change and stays arrow-point cursor.
How to fix that?
<script language="javascript" type="text/javascript">
designer('content');
function designer(editor) {
var browser = navigator.userAgent.toLowerCase();
isIE = (browser.indexOf("msie") != -1);
document.writeln('<iframe id="' + editor + '" width="600px" height="600px"></iframe>');
var edit = document.getElementById(editor).contentWindow.document;
edit.designMode = "On";
if (!isIE) {
document.getElementById(content).contentDocument.designMode = "on";
}
}
</script>
Maybe this page will help?
Try CSS, that should switch the cursor for you.
iframe{cursor:crosshair} //all iframes on page
or
#content{cursor:crosshair} //just the element with the id "content"
Question? where is the variable content set in the call: document.getElementById(content).contentDocument.designMode = "on";
Do you mean editor as in: var edit = document.getElementById(editor).contentWindow.document;
Okay, I see your problem, link to http://devedge-temp.mozilla.org/viewsource/2003/midas/01/example2-index.html has the same issue and that's the Mozilla way.
Your line:
if (!isIE) {
document.getElementById(content).contentDocument.designMode = "on";
}
Should almost certainly read:
if (!isIE) {
document.getElementById(editor).contentWindow.document = "on";
}
As it stands you're asking non-IE browser to find an element with id null, rather than an element with id 'content'.
However, that won't get you a text caret in your IFrame, even if it does make it editable.
The best I could come up with was:
document.getElementById(editor).contentWindow.document.style.cursor = "text";
Which turns the cursor into a caret on the first line of the iFrame (i.e. at the top), presumably because that's the only editable bit at that point.
You have to set this property when the iframe loads.
var edit = document.getElementById(editor).contentWindow.document;
edit.addEventListener("load", function() {
edit.designMode = "On";
}, false);

Events Overwritten in ASP.AJAX on IE7

Greetings!
I'm calling a Web service from Javascript when a user clicks on a link. I need to get the coordinates where the user clicked so that I can display a DIV in an appropriate location. My client-side script looks like the following:
var g_event;
function DoWork(event, theId)
{
if (IsIE())
g_event = window.event;
else
g_event = event;
Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}
function DoWorkSuccess(result)
{
var l_elemDiv = document.getElementById("content-area-div");
DisplayAreaDiv(g_event, l_elemDiv, result);
}
It's used like this:
Help
This works great in Firefox, Safari, and Opera. In IE7, not so much. For example, if I place the following code at the end of both the DoWork() and DoWorkSuccess() functions:
alert(g_event.clientX + ", " + g_event.clientY);
In IE, I'll get two alerts; the first one has correct coordinates, but the second one (which displays on top of the first one) is simply "[object]". Since that "[object]" one is the last one, my DIV is incorrectly displayed in the top left of the browser window. Is there a way I can prevent IE from giving me a second "bad" event? Thanks.
Why not extract and save the coordinates in DoWork and simply use them in DoWorkSuccess rather than saving the event. Of course this won't work if there is more data you are extracting from the event.
var client_x;
var client_y;
function DoWork(event, theId)
{
var g_event;
if (IsIE())
g_event = window.event;
else
g_event = event;
client_x = g_event.clientX;
client_y = g_event.clientY;
Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}
function DoWorkSuccess(result)
{
var l_elemDiv = document.getElementById("content-area-div");
DisplayAreaDiv( { clientX : client_x, clientY : client_y }, l_elemDiv, result);
}
Have you tried setting window.event.cancelBubble = true in your DoWork function?
If not, quirks mode has good article on events and event bubbling - http://www.quirksmode.org/js/events_order.html that has helped me a lot with these kinds of issues.

Resources