I need to create a new top level window or a child window based on the action of the user and i'm using javascript to know the action that has been taken. I'm using the Ti.UI.createWindow() for this and I have tried it with all the possible variations of it i.e null, sending the url, sending the options object but I couldn't get result from any of them. Could anyone show me how to create both a new top-level window and a child-window, I know it sounds silly but I can't get it to work. I'm using Tide SDK 1.3.1 beta on windows 7
P.S: The Ti.UI.currentWindow is working fine and I could change the width and height by using the set methods.
I've figured it out that to create a new child window we need to use the "open()" method after the createWindow() call.
Example:
Ti.UI.createWindow("app://example.html").open();
Ti.UI.createWindow is the way to go. You also need to actually "show" a created window, for it to show up, maybe you forgot to do that?
Example:
var new_window = Ti.UI.createWindow("example.html");
new_window.show();
Related
I currently have a Chat application which opens a new Chatwindow for every Chat (just like on facebook & co). To get this working so far I did some weird hacks since all of the n open chatwindows use the same $scope Variables. This is neither good programming nor does it help with bugfixing later on.
Therefore I'd like to redesign the chat part of my application and use one MessageCtrl instance for every Chatwindow. Is this possible in angular.js and if yes, how could I implement it?
If not, can you give me some guidelines on how to implement it "the angular way"?
edit: What I'm currently doing:
I create the Chatwindow from the MessageCtrl and save the necessary data into a MessageService. Since the next time a user writes a message in one of the Chatwindows I dont know if the $scope Variables are set correctly I check the MessageService again to find the correct Chat.
The problem is currently the only way of knowing what the correct chat is for me by saving the chat id in the parent <div id=<chatId> of the chatwindow. Thats far from good, but the only solution I got working so far
edit2: my code:
When a user starts a new Chat the following happens in some Ctrl:
`$rootScope.newChat = {roomId: roomId};
the MessageCtrl listens on this:
$rootScope.$watch('newChat', function (newVal, oldVal) {
startChatWindow();
// other preperation like setting $scope.roomId
}
startChatWindow() just appends the following html:
var $el = "<div id='" + $scope.roomId + "'class='bottomChat'>";
<!-- other things, like displaying the old messages -->
</div>";
$("#messageTab").append($compile($el)($scope));
PS: by chatwindow I just mean a visually appearing window, in reality it's just a styled like a window. This also means that every chatwindow uses the same messageCtrl. Which also means that I loose reference to e.g. $scope.roomId
edit3: SOLUTION
after removing the jQuery code and creating a directive every chatWindow has it's own Ctrl.
I am currently building a website that uses windows to load in new content via ajax. These windows are allowed to contain the same page as in another window using the same javascript. Currently I assign a unique id to the new window which it then stores for later use.
Once the code is loaded in, all the ids in that window are converted by adding on to them a unique_id. ie "box" becomes "box_win1". I then send this id to the javascript by assigning it to a variable so it can be used in document.ready function.
The pseudo code for the window is like the following:
document.ready{
var temp_id=id+1;
$("#mybox" + temp_id).val("abc")
//run some startup stuff
}
I am just wondering is there a better way to do this. As I find if I open to many new windows all at once the temp_id conflicts and goes to the wrong window.
I would like to some how create an instance of the code but I am not sure how. I cannot use global functions however as that may cause naming conflicts.
put this into a function
function callMe (){
var temp_id=id+1;
$("#mybox" + temp_id).val("abc")
//run some startup stuff
}
you can use callMe() anywhere then
I want to get the references of all already opened child windows. is there any way? I am not using child = window.open(....) just using window.open(....) and opening multiple child windows.
If you don't want to change your current code, you can simply override window.open() function:
var openedWindows = [];
window._open = window.open; // saving original function
window.open = function(url,name,params){
openedWindows.push(window._open(url,name,params));
// you can store names also...
}
Run this code before calling window.open(). All the references to the opened windows will be stored in openedWindows array. You can access them anywhere you want
I don't believe you can, unless you know the windows' names, which I'm guessing you don't. (If you know their names, you can use window.open("", "name") to get a reference to them.)
The better option is, of course, to remember the reference returned from window.open in the first place — but you know that. :-)
Ok, I used the answers to this question in Oracle CRM onDemand to disable a select in a popup window executing the script from the parent window, and it worked! (I have no control over the generation of popup windows, they are opened by the application framework)
Let's see how I did it:
Context: In a detail page the user can add some info by clicking in a magnifying glass icon >>> a new window opens containing a search form, but a select is disturbing the administrator: If the user change its default value he/she will gain access to forbidden records!! Oh my God!
First Approach: Disable that select now!!
Attempt: I found the image's onclick attrib with my browser's dev tools (F12). There was a openAssocPopup method, and then i knew the name of the child window: 'OccamPopup1' :)
Okay! So let's do some magic (executed at the parent window):
window.open("","OccamPopup1").document.getElementById("frmSearch.AQ").setAttribute("disabled", true);
I think this may help, as this question helped to me too. You were right. Now i'm trying to wrap the child's document object within the parent's jQuery object so i can gain access to the entire child's DOM... but this is another story...
You would be best to name the windows using a prefix and a counter.
I needed to detect if a named window (i.e. CBCheckout) was already open and used this:
var signupWindow = window.open('','CBCheckout','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1');
try {
if (signupWindow.document.location.href == "about:blank") {
signupWindow.close();
signupWindow = undefined;
}
} catch (e) { }
This recaptured the reference to the named open window. If it didn't exist, you'd see a small window popup for a second.
If you know the possible names of the windows, you can cycle through the names, attempting to locate them.
I know that for safety reasons that this is not easy to achieve, however there would be a way to do so as firebug does...
Please help, would like to invoke some script in the page's context to achieve some effect...
Basically, I would like to achieve two functionality:
1. add jQuery to any web page automatically if not already exist.
2. when open certain address, call a method of that page to auto notify the server. (an ajax functionality of the page)
I have tried to inject on the body, no luck.
tried to get the window object, which however do not have access to call the function.
Will try to change the location to something like: javascript:alert('test inject');
Many thx.
OK, after reading some official documentation and the GreaseMonkey's source, I get the following method which basically works for me.
Hope it will save sb's hour:
var appcontent = document.getElementById("appcontent"); // browser
if (appcontent) {
appcontent.addEventListener("DOMContentLoaded", function (evnt) {
var doc = evnt.originalTarget;
var win = doc.defaultView;
var unsafeWin = win.wrappedJSObject;
// vote.up is the function on the page's context
// which is take from this site as example
unsafeWin.vote.up(...);
}, true);
}
}
Greasemonkey does that. If you are developing your own extension with similar functionality, you can use Components.utils.evalInSandbox.
I have TestGen4Web script for automating testing on a web-based user interface that has a popup window (hey i didn't write that ui..). In order to write a complete test script that branches the flow based on the some presence of some content in the popup window, I need to write a simple if condition that does something like if document.getElementById("xyz").value - that will run on the popup window and not the parent window.
Any ideas on how to accomplish this? currently, the condition fails because it runs on the parent window.
Also, how to extract some text from the dom and spit it out to a file at the end of the test?
Talked with the author of TestGen4Web. He concluded this was a bug and will be fixed in the next release. Here is the email with the temporary workaround fix:
I have a fix for your problem - which I will add in the next release.
Until then, you can use this patch.
Under your profile's
extensions/{3c20433a-61bc-42fe-831d-415860e17283}/chrome/recorder/cont
ent/
directory,
find recorder.js under the extension installation directory.
in recorder.js, find the method named
Recorder.prototype.fixAction = function(action) {
just before the return method, add the following 2 lines.
newAction.winref = this.fixDatasetsAndVariables(newAction.winref);
newAction.pagerefreshed =
this.fixDatasetsAndVariables(newAction.pagerefreshed);
restart firefox, and run your test.
Hope that solves your problem. Let me know if there are more issues
with the fix.
outside your loop initalize a loop count variable initialize it to
"1" ('count', in the attached example) 2. replace all "tg4wnamed1" with
"tg4wnamed${count}"
outside your loop initalize a loop count variable initialize it to
"1" ('count', in the attached example) 2. replace all "tg4wnamed1" with
"tg4wnamed${count}"