Titanium titlebar button to toggle about screen - javascript

Trying to get a button working in the titlebar is becoming a little difficult. At present the button opens when clicked (calls a window with a webview), and closes when an html button is clicked. But only once. The issue is that after the window is closed, the titlebar button seemingly wont reopen the window...
This is probably a simple error, but one i'm having difficulty finding an answer to.
My app.js:
var infoBtn = Titanium.UI.createButton({
title:'Info'
});
// ABOUT
var win0 = Titanium.UI.createWindow();
var webview0 = Titanium.UI.createWebView({url: 'about.html'});
infoBtn.addEventListener('click', function() { win0.open(); });
Ti.App.addEventListener('closeAbout', function() { win0.close(); });
win0.add(webview0);
win0.hideNavBar();
My about.html:
<head>
<script type="text/javascript" charset="utf-8">
function closeAboutBtn() {
Ti.App.fireEvent('closeAbout');
}
</script>
</head>
<body>
Return to App
</body>
Would anyone have any ideas on how to fix so the about button shows the content when pressed every time?

First quick response would to be just "hide" the window instead of closing it.
verified:
The only way I was able to consistently get he window to hide and show is as follows
// listener assigned to info button
infoBtn.addEventListener('click', function() {
Ti.API.log('info button clicked, show window');
win2.open();
win2.show();
});
// Listener assigned to close in about window
Ti.App.addEventListener('closeAbout', function(data) {
Ti.API.log('info button clicked, close window');
win2.close();
win2.hide();
});

Related

Confirm close window popup does not appear on first time

I am trying following code to confirm user if they really want to close window.
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit() {
return "You have attempted to leave this page. Are you sure?";
}
</script>
But it does not work when my page load and I try to close page [X] without clicking anywhere on page. Yes it does appear when I click somewhere on page then close [X] window. I don't know why do I need to click somewhere on page and then close window.
What I tried so far but nothing works.
window.focus() on document ready as it gets focus on window.
$('#someElementOnpageId').click() as it gets auto click on document
ready.
Can anyone please suggest what should I do?

How to close color box popup on browser back button

I want to close my color box popup on browser's back button click.
I used an iframe and inside the iframe there are many links. When user click on particular link then a color box popup will open.
Currently after opened the popup if user click on back button then popup is not closing.
So i want such a functionality that if user click on back button then popup will be close and also page should not go to back (Disable back button).
I have used the following code but it's not working for me.
<script>
$(document).ready(function() {
function disableBack() { window.history.forward() }
window.onload = disableBack();
window.onpageshow = function(evt) { if (evt.persisted) disableBack() }
});
</script>
Please give me any suggestion to close the color box popup on back button or disable the back button completely.
You should use window.location.hash, and window.onhashchange.
Basically, after popup open, you change hash to something (like window.location.hash = "popup_opend").
Then when user clicks back, that back click will remove the hash you just added.
You just need to handle window.onhashchange to check for that and close the popup.
Of course, hope you don't have any other code that manipulate the hash.

Jquery Show Popup only when window is closed

I am trying to display a confirmation message when the user closes the browser/tab and not when any of the links on page is clicked.
I have got the first part of displaying the message on window close working nicely but problem is that the message/alert is displayed also when user clicks on any link on the page.
I have got code from somewhere to prevent this behavior but still when ever any link is clicked the alert pops up.
Here is the code:
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/backfix-min.js"></script>
$(document).ready(function() {
$(window).bind('beforeunload', function(e){
$("#lead-gen-modal").dialog("open");
// This line only appears in alert boxes for IE
return "Wait\! Don\'t Go\! We have a special offer for you\. Stay on this page to receive big savings\!";
});
$("a").click(function() {
window.onbeforeunload=null;
});
});
just use a global variable
and set it to false when clicking a link.
var key = true;
$(window).bind('beforeunload', function(e){
if(key)
$("#lead-gen-modal").dialog("open");
});
update :
$(document).on("click","a",function() {
key=false;
});
or if you just want to prevent closing window you can do this :
window.onbeforeunload = function(e){
if(key)
return false;
}
I think you are looking for something like this.
$(window).unload(function() {
alert("bye");
});
If that does not work on Chrome try this
$(window).on('beforeunload', function() {
return "bye";
});
jQuery API: unload() http://api.jquery.com/unload/

Popup box on page exit

What I am trying to do is make a pop-up box any time a page exits or is navigated away from. Right now I have
<script type="text/javascript">
function box()
{
var r=confirm("Message");
if (r==true)
{
window.location.href="yes.html";
}
else
{
window.location.href="no.html";
}
}
</script>
<body onunload="box();">
I have 2 problems with this:
It only shows the box if you actually navigate away from the page, refresh, new url etc. If you exit the tab or browser, the box doesnt pop up.
No matter what button you press, it just sends you where you tried to go originally, it never sends you to no.html or yes.html.
Could someone tell me how this is possible?
Try this:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
setTimeout(function() {
setTimeout(function() {
window.location.href="yes.html";
}, 1000);
},1);
return "Message";
}
</script>
You can only catch the stay on the page option, you cannot override a user leaving the page. similar to: Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

Toggle DIV with JQuery

I have a FAQ area on my page that has all of the questions in a list and when a user clicks on a title, a DIV with the answer will expand into view. However, I'm having trouble when it comes to closing the answer DIV layer. One of two things happen...
This one will simply open and close each DIV layer individually therefore multiple answers can be open at once. I want only one open, when a user either clicks the same title or another title, the currently open layer should collapse.
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".faq_answer").hide();
jQuery(".faq_heading").click( function() {
jQuery(this).next(".faq_answer").slideToggle(500);
});
});
</script>
This one will collapse whatever layer is currently open when another title is clicked (which is good). However, when the SAME title is clicked it closes it and then reopens it.
<script type="text/javascript">
jQuery(document).ready( function() {
jQuery(".faq_answer").hide();
jQuery(".faq_heading").click( function() {
jQuery(".faq_answer").hide(500);
jQuery(this).next(".faq_answer").slideToggle(500);
});
});
</script>
Inside your click handler, instead of this:
jQuery(".faq_answer").hide(500);
Try this:
jQuery(".faq_heading").not(this).next(".faq_answer").hide(500);

Categories