Creating a modal window onload of a page for user feedback - javascript

I have to create a modal window to display a popup or a modal window to get the feedback from the user for our intranet. This window should have a checkbox which says "do not ask this question again".
I tried creating this window using jquery but I dont understand how to do it. I even tried to google it but not getting proper answers. Can anyone please help me with this.
I am new to jquery.I have seen many sites where they have created modal windows but they use php and I cant. Please help me with jquery, jsp or javascript code for this purpose.
A screenshot from the use case document is attached.
Any help is appreciated. Thanks in advance.
p.s. I am using websphere portal.
Sorry the image wasnt allowed..
The below mentioned code also doenst work. Plz help.
<html>
<head>
<%#page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.accessitservicesfeedbackpopup.*" %>
<%# taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%#taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<portlet:defineObjects/>
<link rel="stylesheet" type="text/css" href="<%= renderRequest.getContextPath() %>/style.css"/>
<link rel="stylesheet" type="text/css" href="<%= renderRequest.getContextPath() %>/jqModal.css"/>
<script language="javascript" type="text/javascript" src="<%= renderRequest.getContextPath() %>/jqModal.js"></script>
<script language="javascript" type="text/javascript">
function confirm(msg,callback) {
$('#confirm')
.jqmShow()
.find('p.jqmConfirmMsg')
.html(msg)
.end()
.find(':submit:visible')
.click(function(){
if(this.value == 'yes')
(typeof callback == 'string') ?
window.location.href = callback :
callback();
$('#confirm').jqmHide();
});
}
$().ready(function() {
$('#confirm').jqm({overlay: 88, modal: true, trigger: false});
// trigger a confirm whenever links of class alert are pressed.
$('a.confirm').click(function() {
confirm('About to visit: '+this.href+' !',this.href);
return false;
});
});
</script>
</head>
<body>
view (confirm)
<!-- Confirm Dialog -->
<div class="jqmWindow" id="confirm">
<div id="ex3b" class="jqmConfirmWindow">
<div class="jqmConfirmTitle clearfix">
<em>Close</em>
</div>
<div class="jqmConfirmContent">
<p class="jqmConfirmMsg"></p>
<p>Continue?</p>
</div>
<input type="submit" value="no" />
<input type="submit" value="yes" />
</div>
</div>
</body>
</html>

There is nice jQuery dialog you can use. Just download jQuery and jquery ui (both js and css) and include to your project. It works prefectlly.

Related

JavaScript doesn't work with bootstrap 4 + thymeleaf

I'm developing a web app with Spring Boot, Bootstrap 4 and Thymeleaf.
I want to show a bootstrap alert, and then, it hides automatically after seconds (just like a "sucessfully" notification).
I have found a lot of solutions, but all of then need JavaScript. When I tried to use JS on my project, it doesn't work.
I use a default template, which is used in the others views through layout:decorate="~{default}". In this default template, I have the Bootstrap link and scripts:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
...
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
If a put in any view the following code, it does nothing.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
...
</head>
<body class="text-center">
<div layout:fragment="content">
<div class="product-options">
<a id="myWish" href="javascript:;" class="btn btn-mini">Add to Wishlist </a>
Purchase
</div>
<div class="alert alert-success" id="success-alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>Success! </strong> Product have added to your wishlist.
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#success-alert").hide();
$("#myWish").click(function showAlert() {
$("#success-alert").fadeTo(2000, 500)
.slideUp(500, function () {
$("#successalert").slideUp(500);
});
});
});
</script>
...
</div>
</body>
NOTE: This is just an example to check that JS doesn't work. I takes it from this post.
When I run this code, the alert is showed, but it never disappears. I have tried with a lot of scripts and never work.
Could be a compatibility version problem?
Hi I think this post address your problem:
Why does jQuery throw the error `fadeOut is not a function'?
In this line <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> you use the slim version of Jquery not the full-one, this prompt when I click to "Add to Wishlist" link" a TypeError in the Firefox develloper tool console.
TypeError: $(...).fadeTo is not a function, this means that the Jquery javascript object $("#success-alert") doesn't have attached a fadeTo function.
You can get the full minified version here: https://code.jquery.com/
Snippet from https://code.jquery.com
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
PS: If you don't need SRI you can remove integrity and crossorigin attributes.

Dropzone.js -- Error when loading, weird long message

Im trying to do a simple dropzone file uploader. Im not interested in the server side as Im not doing this seriously, just trying the js for the front end. Everything seems ok, the load bar works fine, but then it always show the X image and then I get this insanely long message that contains html.
This confuses me because from the examples ive seen, if there is an error it will display the string from the js. I dont know why it's showing this long message.
Does it have anything to do with the "action" or "file" type?
A screenshot is here
https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/13310379_496643860530613_5508631554600071626_n.jpg?oh=1c25de2a0cb0957a68c1e8e2905b52df&oe=57DC5CA0https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/13310379_496643860530613_5508631554600071626_n.jpg?oh=1c25de2a0cb0957a68c1e8e2905b52df&oe=57DC5CA0
Edit:
My HTML is this:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="assets/js/dropzone.js"></script>
<script src="assets/js/dropzone-amd-module.js"></script>
<link href="assets/css/dropzone.css" type="text/css" rel="stylesheet" />
<link href="assets/css/basic.css" type="text/css" rel="stylesheet" />
<link href="assets/css/Style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="dropzone">
<form action="/file-upload" class="dropzone dz-clickable" id="demo-upload">
<div class="dz-default">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</div>
</form>
</div>
</body>
</html>
My bad, didn't know you were using the default Dropzone.js. I'd remove the downvote if I could but it's locked in now.
Try
<form action="UploadImages" class="dropzone">
</form>
Remove the <div id="dropzone"> too. You already specify dropzone for the form, so wrapping it in a div with id of dropzone makes no sense.
jsFiddle: http://jsfiddle.net/3zhyg73u/85/ so you can compare your code and see why it's not working.
sorry, Im pretty new to this but i think it's because the errorMessage from the error event receive's a string containing HTML when a failed post request is sent out. you can change the message by doing this. this isn't the best method but it works :/ ohh and i was using jquery for this particular project
var myDropzone = new Dropzone('#icDropZone', {
url: "/file/post",
error: function(response, errorMessage, xhrObj) {
if(response.status === "error") {
$('div.dz-default.dz-message > span').show(); // Show message span
$('div.dz-default.dz-message').css({'opacity':1, 'background-image': 'none'});
$('.dropzone .dz-preview .dz-error-message').attr('style','display:block;opacity:1;top: 150px;background:#D44F4F;');
$('.dropzone .dz-preview .dz-error-message span').html('Error uploading image')
}
}
});

onclick to redirect to next page not working in phonegap

<html>
<head>
<title>Quiz Application</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
function ready()
{
if(document.getElementById("rb2").checked)
{
alert("correct");
}else if(document.getElementById("rb1").checked)
{
alert("incorrect");
}
else
{
alert("incorrect");
}
}
function nextPage()
{
window.location = "next.html";
}
</script>
</head>
<body>
<form method="post">
<center><h1>Quiz Application</h1></center><br><br>
<center>What does JVM stands for ?<br><br>
<radiogroup>
<input type="radio" id="rb1"/>Java Vendor Machine<br>
<input type="radio" id="rb2"/>Java Virtual Machine<br>
<input type="radio" id="rb3"/>Java Viral Machine<br>
<input type="submit" id="sub" value="Freeze" onclick="ready();"/><br>
<input type="submit" id="next" value="Next Question" onclick="nextPage();"/></center>
</radiogroup>
</form>
</body>
</html>
Above is my code for redirecting my page to next page after click event.
But it is not redirecting to next page.I went through many questions on stackoverflow as well but didnt succeed.
Please help me .
Thanks in advance.
What are you doing there? If you're doing it with jQuery mobile an example would look like this:
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"> </script>
</head>
<body>
<div data-role="page" id="page1">
<p>This is page 1. If you want to go to Page 2 click here.
</div>
<div data-role="page" id="page2">
<p>This is page 2. If you want to go back to Page 1 click here.
</div>
</body>
</html>
Changing a page by function could look like this:
function changePage() {
$.mobile.changePage( "#loginPAGE", { transition: "none", changeHash: true });
}
Here's a pen: http://codepen.io/anon/pen/gaeoQE
Frameworks - Mobile App Development
So like i said in my comment, i would recommend you to use a framework. Since i don't know, how conversant you're in JavaScript and anything else i think you should start with jQuery. For mobile App development it's not one of the best frameworks in my opinion but it's easy to learn and thats important for you to start.
So jQuery is a thing for your website. For your mobile application you need jQuery mobile.
You go to that websites and download both. When your download is finished, you're going to open up your index.html and add the scripts to your <head></head> section so that it looks like the following:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
These things are important. Also the order in which you include the scripts is important.
After adding this to your header, you're able to access a whole bunch of functions. All of the features are testable inside a demo environment which can be found over here: jQuery mobile Demos (1.4.5).
When you have finished that, you're going to copy my code from my pen into your <body></body> and it should work. For changing a page via javascript you can use the function changePage() which i've already posted before.
I hope this will help you, if not please let me know where exactly i can help you.
I found out the solution for my query . i just wrote the following function onClick of a button (input type should be button and not submit then only it will work)
function nextPage()
{
document.location="nextpage.html"; //instead of window.location
}

How to apply Css/JQuery files to an external page inside Android WebView

Not sure if what I had in mind is possible or not, but why now.
I have a MVC4 Master page as follows
<head runat="server">
<meta charset="utf-8" />
<title>RYTE HCMS</title>
<meta name="viewport" content="width=device-width" />
<link href="<%: Url.Content("~/favicon.ico") %>" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" href="~/Content/jquery/jquery.mobile.theme-1.4.3.min.css" />
<link rel="stylesheet" href="~/Content/jquery/jquery.mobile.icons.min.css" />
<link href="~/Content/jquery-ui.datepicker.min.css" rel="stylesheet" />
<link href="~/Content/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" />
<%: Scripts.Render("~/bundles/modernizr") %>
<style type="text/css">
.wrap {
white-space: normal !important;
}
</style>
</head>
<body>
<div data-role="page" data-theme="a" data-url="master-page" id="master-page">
<div data-role="header" data-position="fixed">
<asp:ContentPlaceHolder ID="Header" runat="server">
<h1>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</h1>
<% Html.RenderPartial("LoginUserControl"); %>
</asp:ContentPlaceHolder>
</div>
<div data-role="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</div>
<script src="<%=Url.Content("~/Scripts/jquery-1.11.1.min.js")%>"></script>
<script>
$(document).on("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="<%=Url.Content("~/Scripts/jquery.mobile-1.4.5.min.js")%>"></script>
<script type="text/javascript">
$(document).on("pageinit", "#master-page", function () {
$(document).on("swipeleft swiperight", "#master-page", function (e) {
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel (and v.v.).
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData("panel") !== "open") {
if (e.type === "swipeleft") {
$("#right-panel").panel("open");
} else if (e.type === "swiperight") {
$("#leftpanel").panel("open");
}
}
});
});
</script>
<asp:ContentPlaceHolder ID="ScriptsSection" runat="server" />
</body>
I want to load and apply CSS/JQuery in the Android WebView. I want to keep the files in android mobile app and apply them as the page loads inside the webView.
If I don't load these files in specific order the design breaks. The reason I want to do this to make sure user don't feel its a web app. At present at each refresh/reload it takes about 1-2 seconds for jquery mobile and css to load.
Since MVC4 pages are compiled on remote server, Is it possible?
Okay, so the comment on your question basically sums it up. You need to add the js/css code into your assets files.
If you want an example, you can take a look at this sample project (I only load js code, but it's the same principle for css) here
To go over the general idea:
Make your webview use a custom WebViewClient (called MailWebViewClient in the example). You don't need a custom webview (as was done in the example) wv.setWebViewClient(webViewClient);
In your webview client, override the onPageFinished() method and load your javascript code in a string (src) view.loadUrl("javascript: " + src);
That's it. It should work fine
In the example, I'm loading a script that will resize all tables and images to fit inside the webview (a common requirement for android). There's also some haphazard linkify code (to identify and mark links). I wouldn't use the js code, since it's a little buggy, but it's a good example for the principle.
put All Css and JS in assets folder.
and try to load web view with :
webView.loadDataWithBaseURL("file:///android_asset/", <HTMLDATA> ,"text/html", "UTF-8", null);

How to load this JavaScript when page Loaded

I'm a newbie to programming and I want to ask something about Javascript.
How to make this script is displayed when the page is loaded?
I want to make "1 people online" with this jQuery pop up.
$(document).ready(function() {
$.sticky('1 user seen this hotel!');
});
Can you all tell me how to use it and how to modify it?
I get this function from http://www.jqueryrain.com/?uOBwr_rL
Please help me.
Thanks, gbu
Sample HTML Page
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="sticky.min.js"></script>
<link rel="stylesheet" href="sticky.min.css" type="text/css" />
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$.sticky('The page has loaded!');
});
</script>
</body>
</html>
Please make sure you save this html content as HTML page in the same directory as your sticky.min.js & sticky.min.css files.
If you don't need the sticky functionality (i.e. if it's okay for a user to close the window), you can use an alert:
$(document).ready(function() {
alert('1 user seen this hotel!');
});
Or the jquery dialog: http://jqueryui.com/dialog/

Categories

Resources