Here is my problem: chrome does not allow new tab to be opened without involvement of user action( it opens a new window instead which I do not want), so to tackle that I want the new page to be opened when user clicks ok in confirm box.
unfortunately, bool= window.confirm('sure?') does not count as user action, so I need a simple code, which would look like normal confirmation box, but instead of ok button, there would be an anchor whose url i can set dynamically.
P.S : I believe it can be done using JQuery-UI, but I want to do it just using javascript and JQuery, this is targeting chrome browser only( that's my only silver lining).
Try to use a modal It looks like a Confirm box but is created by you and you can style it.
var r = confirm("Press a button!");
if (r == true) {
window.open("your url","_blank");
}
if i got what you actually need, You can use simple js.
Related
Using Cognos Analtyics 11.1.7IF9.
I have a user who, oddly enough, wants Cognos to make his workflow more efficient. (The nerve!) He thinks that if he can use the TAB button to navigate a prompt page, he'll be faster because he never needs to reach for the mouse.
To test this I created a simple report with a very simple prompt page using only textbox prompts. As I tab I notice it tabs to everything in the browser: browser tabs, the address bar, other objects in Cognos, ...even the labels (text items) I created for the prompts. Oh... and yes, at some point focus lands on a prompt control.
Within Cognos, I see that the tab order generally appears to be from the top down. (I haven't tried multiple columns of prompts in a table yet.) I must tab through the visual elements between the prompts. Also, while value prompts get focus, there is no visible indication of this.
Is there a way to set the tab order for the prompts on a prompt page?
Can I force it to skip the non-prompt elements?
Can the prompts be made to indicate that they have focus?
I tagged this question with javascript because I figure the answer will likely involve a Custom Control or a Page Module.
Of course, then I'll need to figure out how all this will work with cascading prompts and conditional blocks.
I found a similar post complaining about this being a problem in Cognos 8. The answer contains no detail. It just says to go to a non-existent web page.
I had the same frustration as your user and I made a solution a while back that could work for you. It's not the most elegant javascript and I get a weird error in the console but functionally it works so I haven't needed to fix it.
I created a custom control script that does 2 things on a prompt page.
First, it removes the ability to "select" text item elements on the page. If you only have text items and prompts on the page it sets it's "Tabindex" to "-1". This allows you to tab from one prompt field to the next without it selecting invisible elements or text elements between prompts.
Secondly, if you press "Enter" on the keyboard it automatically submits the form. I am pasting the code below which you can save as a .js and call it in a custom control on a prompt page. Set the UI Type to "None"
define( function() {
"use strict";
function AdvancedControl()
{
};
AdvancedControl.prototype.initialize = function( oControlHost, fnDoneInitializing )
{
function enterSubmit (e)
{
if(e.keyCode === 13)
{
try {oControlHost.finish();} catch {}
}
};
function setTab () {
let nL = [...document.querySelectorAll("[specname=textItem]")]
//console.log(nL)
nL.forEach((node) =>{
node.setAttribute('tabindex','-1')
})
};
setTab();
let exec_submit = document.addEventListener("keydown", enterSubmit, false);
try {exec_submit;} catch {}
fnDoneInitializing();
};
return AdvancedControl;
});
I have the standard tabs setup using Bootstrap 3. Each tab is a form into which the user inputs information. Now there is a save button at the bottom of each form which will save the information in the current tab, but what I'm looking to do is enable the user to click a different tab at the top of the page, and be given a warning of
var areYouSure = confirm('If you sure you wish to leave this tab? Any data entered will NOT be saved. To save information, use the Save buttons.');
with an OK or Cancel button. If they click OK then they go to the tab they clicked, and if they hit cancel, they stay on the current tab. Anybody any idea how I can do this? I've been trying to get this all day, but with no luck. Should I even be using Bootstrap tabs or would it be easier to build my own tabs functionality instead of over-riding bootstrap's tabs?
Per the Bootstrap 3 docs, you can set up something like this. In your tab button listener, show a confirm box, then add logic to handle that response:
$('#myTabs a').click(function (e) {
e.preventDefault()
var areYouSure = confirm('If you sure you wish to leave this tab? Any data entered will NOT be saved. To save information, use the Save buttons.');
if (areYouSure === true) {
$(this).tab('show')
} else {
// do other stuff
return false;
}
})
You could add a class to your tabs and then use an on click function where you'd fire a modal or bootbox confirm asking the user if they want to continue to the new tab. If they select no, you prevent the new tab from loading, if they select yes, you continue.
https://api.jquery.com/click/
http://bootboxjs.com/examples.html
I need to prompt the user to a site usability survey when the user navigate away from the site or try to close the site window. For example, when the user closes the window of my site, I want to show a prompt to say "do you want to take a survey?" , if the user clicks yet, open a new window with the survey link.
Is there a way in GWT to achieve that?
I have tried using
Windows.addWindowCLosingHandler
but that only gave me the ability to set a message to ask if the user want to stay on the site or now using ClosingEvent event , event.setMessage("sure?");
thanks
You can use window.onunload but that will be called whenever the user changes the page
Also see here: How to catch user leaving a page and cancelling it
Use the unload method on the body:
<body onUnload="unloadFunction(); return false;">
Then something like this for your js:
function unloadFunction()
{
if (confirm("Would you like to take our servey?"))
{
window.location.href = 'location_of_your_survey'
}
return false;
}
I am facing an issue where a link on my website opens in a new window if you simply click on it. However, if you right click and say open in new window or new tab, it opens the same window (URL) again from where the link is clicked.
Self Service Option is a link and the JSP calls a function getSelfServSite() when the link is clicked. This is how the code flows in my case
function getSelfServSite()
{
getToTheLink("${myConfigInfo.selfServiceURL}");
// this is because the URL is configurable
}
function getToTheLink(url)
{
window.open (url, "currentWindow", "");
}
What am I doing wrong. I want it to go to the right link no matter how the user click it.
Please advise. Thanks
I would suggest doing something like this.
Setup an event handler to capture when a user right clicks. When they do, run you function to get the selfServSite url, and set the links href attribute to be the new Url.
here is some info on capturing the right click event.
How can I capture the right-click event in JavaScript?
EDIT: Based on our discussion in the comments, here is a revised solution.
When the page is opened in a new window from a right-click, it has "#id-card" appended to it, so what you need to do is check for that value when the page first loads, and if it's there, run the same javascript function that gets run when the user left-clicks on the link.
You can check for this value using the location objects hash property.
http://www.w3schools.com/jsref/obj_location.asp
I am implementing a form which has got links in it,
like this:
<form>
<a>FAQ </a> /* something this way */
<submit button>
</form>
I have to display a confirmation box to the user, if the link is clicked and only when it tries to load the href. In case the user is opening the link in new tab or uses 'CMD-Click' (Mac), the prompt must not be shown.
In Firefox, the browser itself takes care of this when the user tries to navigate to another page when he is in the middle of the form, but I need this functionality to work in all browsers.
Does anyone know how to do this?
that's simple
Google
but i'm not sure if CMD+Click doesn't alert the user. Most of these event can't be controlled by javascript as they are coded into browsers.
Maybe something like this? demo
<form>
FAQ /* something this way */
<submit button>
</form>
$("a").click(function() {
if (!confirm("Do you want to leave?")) {
return false;
}
});
As for not displaying on new tab/new window, there are no such javascript events, thus you cannot capture them.