How to load the page as popup dialog without specifying "data-rel" in the caller link - jquery-mobile

Hi i'm new to Jquery mobile,have some servlet which evaluates username and password from login.html page as,
if(un.equals("user1") && pd.equals("password1")){
RequestDispatcher rd=request.getRequestDispatcher("welcome.html");
rd.forward(request, response);}
else {
RequestDispatcher rd=request.getRequestDispatcher("loginfailed.html");
rd.forward(request, response);}
}
i
what i'm trying is when login fails loginfailed.html should open as a popup dialog showing login failure notice example here. Pls help me to do this..

I've been using this:
http://dev.jtsage.com/jQM-SimpleDialog/
Much easier to open from within javascript than the default jquery-mobile dialog, plus it looks like a dialog in that it does not take up the whole page.

Related

Use Firefox add-on SDK to construct a web page

I would like to build an Firefox extension which after users click it, a web page is dynamically constructed and opened in a new tab.
In "tab" API, I only saw tab.open() open a hyperlink to a remote website. Can I construct a JavaScript variable contains all the HTML contents (Like var page = "blahblah....") and open it? How to do that?
You don't have to dynamically construct it, just put a htm page in your addon and then the link to it will be resource://your addon id/blah.htm. This addon here creates a page: addons.mozilla.org/en-US/firefox/addon/twitch-alarm
You can also create an about:blah url to your page, this shows how to do it without the sdk: github.com/Noitidart/ZooniverseXpert
You don't have to create a html page dynamically but put a html page in your addon and refer it when you open a tab.
tabs.open({
url : self.data.url("js/error.html"),
onReady : function(tab) {
var errorWorker = tab.attach({
contentScriptFile : self.data.url("js/error.js")
});
errorWorker.port.emit("error_page",message);
}
});
Here I am displaying an error page which is stored in my addon and attaching a content script file to dynamically change the contents of html page through message passing between main.js and error page.
Hope it is of some use to you.

URL redirection in jquery mobile

I have 2 pages page1.html and page2.php. I am sending user information (GET) like page2.php?new_user=true. In page 2 the first page has id="Welcome". In page2.php I am redirecting the request to a <div datarole="page" > with id="NewUser"(inside page2.php). I am using javascript to do this $isnew= '<?php echo $_GET["new_user"]; ?>';. Currently I am redirecting using an if condition
if($isnew=="true")
{
window.location.href="#NewUser"
}
The problem is I want to display #NewUser as a dialog and NOT a page. Can anyone give any other possible solution to this?
Thanks in advance.
To show a page as a dialog:
$.mobile.changePage('#NewUser', { role:'dialog'});
jQuery Mobile API - Dialog Widget

in C#, msgbox didn't show

Below is part of my codes in C#, it suppose to send email, show the msg box, then direct to 'Multihotelbook.aspx' page, but the direct to the page without showing the msgbox. i dont know why. need help
emailClient.Send(message);
// Response.Write("<script>window.alert('Email sent')</script>");
//ClientScript.RegisterStartupScript(typeof(Page), "myscript", "<script>alert('Email sent');</script>");
// System.Windows.Forms.MessageBox.Show("Email sent");
// MessageBox.Show("Email sent");
// MessageBoxResult result = MessageBox.Show("Email sent", "Confirmation");
//ClientScript.RegisterStartupScript(typeof(Page), "myscript", "<script>alert('Email sent');</script>");
//ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "confirm('Email sent');", true);
//ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "KEY", "alert('Email sent')", true);
Page.ClientScript.RegisterStartupScript(typeof(string), "alert", "<script>alert('Email sent')</script>");
Response.Redirect("Multihotelbook.aspx");
This... looks like ASP.NET code. There is no MessageBox in ASP.NET. Notice that you had to fully reference System.Windows.Forms, which I imagine you also had to add as a reference. Windows Forms and ASP.NET are two very different things.
What exactly are you trying to accomplish? Showing a JavaScript alert()? If that's the case then you can just include some additional JavaScript code in the response.
Except... you're also doing this:
Response.Redirect("Multihotelbook.aspx");
Which means that the response to the client is being clobbered by a header which tells the client to go to Multihotelbook.aspx. So the client never sees anything else you're including in the response, basically anything in RegisterStartupScript.
After this code executes, the client is going to end up on Multihotelbook.aspx. Unless there's a JavaScript alert() on that page, the browser won't show one.
One approach you could try is to pass a flag to Multihotelbook.aspx, something like Multihotelbook.aspx?emailSent=true and in the Page_Load of that page check for that value and, if it's set to true, include JavaScript code in the page to show the alert() (probably using RegisterStartupScript like you're already trying).

Grails file download does not initiate when called from remoteFunction

In my Grails application, a user can click on a g:link which will call my controller to export certain data to a CSV file. This works with no problems.
I then moved that button to a jQuery dialog box and, when the button is clicked, I use
${remoteFunction(action:'export', onSuccess:'closeMe();', id:courseInstance?.id)}
to call the same controller method and close the dialog box. I've confirmed that the method is actually called, and the dialog box closes. The user is not prompted with the CSV dowmload, however. I'm assuming this has something to do with the remoteFunction, but I'm not really sure. Can anyone explain why this might happen, and a potential fix?
Thanks!
With AJAX requests you can't handle to download content as attachment and so it can't trigger the Save As dialog.
There are a couple of workarounds for this:
Use a plain g:link as before and bind the 'closeMe();' function to the 'click' event. The problem is that you have no control on error or success response.
Use an iframe: You can create a temporary invisible iframe and set its location to the URL of the file to download. It also has the backside of not controlling the success/error response.
The code could be the same as in this answer:
<script type="text/javascript">
function downloadURL(url) {
var iframe;
var hiddenIFrameID = 'hiddenDownloader';
iframe = document.getElementById(hiddenIFrameID);
if (iframe === null) {
iframe = document.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
document.body.appendChild(iframe);
}
iframe.src = url;
}
</script>
And the link
Export

File download from JSF with a rendered response

I have some dynamically generated files which I want my JSF 2.0 app to download for the user. I've been able to get this working using the code found in the solution here :
Forcing a save as dialogue from any web browser from JSF application
and a command button in a form on the page
And that works fine except for one hitch. I'd like to be able to render a message back to the user on the initial page that tells them their file is being processed and to please wait. Obviously the responseComplete call stops that from happening. Is there some way to re-render the submitting page and send back a file from the same button?
No, you can't. You can send only one response back per request. Best what you could do is to use JavaScript to show an initially hidden div or something which contains the message during the onclick. But you'll have the problem that you cannot hide it whenever the download is completed.
An alternative is to store the file on temp disk and return a fullworthy JSF response wherein you display a download link which returns the file from temp disk by a standalone servlet.
I think you can use ajax to solve this. Call the method that creates the file from an ajax action and provide a javascript callback to handle the navigation or to show a layer or whatever
<script type="text/javascript">
function processEvent(data) {
if (data.status == "begin") {
showWaitingLayer();
} else if (data.status == "success") {
hideWaitingLayer();
showDownloadLink();
}
}
</script>
<h:commandLink action="#{myBean.createDocument}">
<f:ajax onevent="processEvent"/>
</h:commandLink>

Resources