Opening an browser + url in Mobicontrol Messagebox - javascript

I'm trying to open an url in browser in Mobicontrol Messagebox when pressing the YES dialog button.
It allows for some very basic javascript / Mobicontrol API scripting.
https://www.soti.net/mc/help/javascriptapi/en/index.html
But so far I had no succes, so was wondering if perhaps anyone knows a very basic javascript function to run an intent/scheme...or something like that.
So far variations of things I used was:
mobicontrol.message.createYesNoDialog('Would you like to open https://google.com ?')
.withCallback(onConfirm).show();
function onConfirm(result) {
if (result.isYesButton) {
mobicontrol.log.info('The Yes button was clicked');
OpenURL();
}
else if (result.isNoButton) {
mobicontrol.log.info('The No button was clicked');}
else if (result.isDismissed) {
mobicontrol.log.info('The dialog was dismissed');}
}
function OpenURL() {
mobicontrol.app.Activity('https://google.com#Intent;action=android.intent.action.VIEW;end');
}
I've also seen a lot of examples of window.open but the API doesn't seem to understand that yet.

Related

jQuery beforeunload reliability [duplicate]

I have a form where the input fields are saved onChange. In Firefox (5) this works even when the window is closed, but for Chrome and IE it doesn't and I need to be sure that I'm saving this data even if they try to close the window after they've typed in a field but an onBlur event hasn't occurred (i.e. they've typed something into a textbox, but haven't tabbed out of it).
I have read the following SO articles on using window.onbeforeunload:
article 1
article 2
if I use the following:
window.onbeforeunload = function() {
return "onbeforeunload";
}
then I get a popup with onbeforeunload in.
but if I try:
window.onbeforeunload = function() {
alert("onbeforeunload");
}
then nothing happens in any browser, even Firefox.
what I want to achieve is:
window.onbeforeunload = function() {
saveFormData();
}
I'd be grateful if someone could point out where I might be going wrong.
You have to return from the onbeforeunload:
window.onbeforeunload = function() {
saveFormData();
return null;
}
function saveFormData() {
console.log('saved');
}
UPDATE
as per comments, alert does not seem to be working on newer versions anymore, anything else goes :)
FROM MDN
Since 25 May 2011, the HTML5 specification states that calls to window.showModalDialog(), window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event.
It is also suggested to use this through the addEventListener interface:
You can and should handle this event through window.addEventListener() and the beforeunload event.
The updated code will now look like this:
window.addEventListener("beforeunload", function (e) {
saveFormData();
(e || window.event).returnValue = null;
return null;
});
There seems to be a lot of misinformation about how to use this event going around (even in upvoted answers on this page).
The onbeforeunload event API is supplied by the browser for a specific purpose: The only thing you can do that's worth doing in this method is to return a string which the browser will then prompt to the user to indicate to them that action should be taken before they navigate away from the page. You CANNOT prevent them from navigating away from a page (imagine what a nightmare that would be for the end user).
Because browsers use a confirm prompt to show the user the string you returned from your event listener, you can't do anything else in the method either (like perform an ajax request).
In an application I wrote, I want to prompt the user to let them know they have unsaved changes before they leave the page. The browser prompts them with the message and, after that, it's out of my hands, the user can choose to stay or leave, but you no longer have control of the application at that point.
An example of how I use it (pseudo code):
onbeforeunload = function() {
if(Application.hasUnsavedChanges()) {
return 'You have unsaved changes. Please save them before leaving this page';
}
};
If (and only if) the application has unsaved changes, then the browser prompts the user to either ignore my message (and leave the page anyway) or to not leave the page. If they choose to leave the page anyway, too bad, there's nothing you can do (nor should be able to do) about it.
The reason why nothing happens when you use 'alert()' is probably as explained by MDN: "The HTML specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event."
But there is also another reason why you might not see the warning at all, whether it calls alert() or not, also explained on the same site:
"... browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with"
That is what I see with current versions of Chrome and FireFox. I open my page which has beforeunload handler set up with this code:
window.addEventListener
('beforeunload'
, function (evt)
{ evt.preventDefault();
evt.returnValue = 'Hello';
return "hello 2222"
}
);
If I do not click on my page, in other words "do not interact" with it, and click the close-button, the window closes without warning.
But if I click on the page before trying to close the window or tab, I DO get the warning, and can cancel the closing of the window.
So these browsers are "smart" (and user-friendly) in that if you have not done anything with the page, it can not have any user-input that would need saving, so they will close the window without any warnings.
Consider that without this feature any site might selfishly ask you: "Do you really want to leave our site?", when you have already clearly indicated your intention to leave their site.
SEE:
https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
I seem to be a bit late to the party and much more of a beginner than any expertise; BUT this worked for me:
window.onbeforeunload = function() {
return false;
};
I placed this as an inline script immediately after my Head and Meta elements, like this:
<script>
window.onbeforeunload = function() {
return false;
}
</script>
This page seems to me to be highly relevant to the originator's requirement (especially the sections headed window.onunload and window.onbeforeunload):
https://javascript.info/onload-ondomcontentloaded
Hoping this helps.
you just cant do alert() in onbeforeunload, anything else works
To pop a message when the user is leaving the page to confirm leaving, you just do:
<script>
window.onbeforeunload = function(e) {
return 'Are you sure you want to leave this page? You will lose any unsaved data.';
};
</script>
To call a function:
<script>
window.onbeforeunload = function(e) {
callSomeFunction();
return null;
};
</script>
Yes what everybody says above.
For your immediate situation, instead of onChange, you can use onInput, new in html5. The input event is the same, but it'll fire upon every keystroke, regardless of the focus. Also works on selects and all the rest just like onChange.

Disable close and minimize option

Am a beginner to javascript, i have a doubt on this following :-
How to disable print popup window close button and minimize.Am working on a web application using java script.
As we all know print function will show a popup and it has a minimize and close button by default.
Is there any way to disable minimize and close button programmatically.
Is there exist any javascript method to do this?
myWindow.print();
Thanks,
Please help.
The 'print' window is created by your browser, not by Javascript (Javascript just says 'hi browser, could you print this for me?). Luckily, browsers do not allow the 'close' and 'minimize' button to be disabled, as this would create a VERY unfriendly user experience (just imagine sites that 'force' you to print a million pages for them). So, there's no 'how to' answer to your question, and that makes the world a better place.
I think print page help user to print it, so you take them to print page instead of minimizing it.. It will automatically go to print page..
function PrintWindow()
{
window.print();
CheckWindowState();
}
function CheckWindowState()
{
if(document.readyState=="complete")
{
window.close(); //you can edit it as you want
}
else
{
setTimeout("CheckWindowState()", 2000);
}
}
PrintWindow();

how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery

how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery..
Have to black ctrl+s --> Do not allow to save the page
Have to black f12 and right click--> Do not allow to inspect/debug/view source of the page
"Do not allow to save the page" - This is impossible, as this would require not delivering the page to the user in the first place.
"Do not allow to inspect/debug/view source of the page" - This is also impossible. In Chrome you can prepend view-source: to the URL, and you can get to developer tools with Menu -> Tools -> Developer Tools. In any case, the browser has to have access to the source code to actually display the page.
What you are trying to do is impossible. There is also absolutely no reason to. (It's also highly annoying to legitimate users who actually want to right click!) If you're trying to do this for "security," this is most definitely not your biggest problem. If there's any insecure information delivered to client side, you have to redesign your entire system immediately.
Forget about it! I can write my own web browser which doesn't have right click, F12 and CTRL+S and I can still see the HTML and Javascript source. I can even do this with telnet.
If your manager gave you such requirements I would tell him to go back to primary school.
I know you can't tell him this. But really:
You can't rely on the fact that some user agents will respect your tricks.
This won't improve security - this will give you nothing.
Just some background information:
Some time ago I've written a script for Selenium WebDriver to control Firefox. I was able to grab any data, read all the scripts and moreover inject my own JS to any website.
You should listen to the comments and answers and provide security on the server side because everything your server sends as a response can be read, saved and processed one way or another.
There are some legitimate reasons for this functionality. We are doing web-based testing in a school district and we have to provide a reasonable assurance that students will not be able to find the source file of a test and download it or email it to themselves during the test. For that reason we have to disable right click and do everything we can to ensure that F12 and Ctrl U does not work. School districts with minimal budgets have no choice but to rely on these tricks to help get more done with less.
<script type="text/javascript">
if (document.layers) {
//Capture the MouseDown event.
document.captureEvents(Event.MOUSEDOWN);
//Disable the OnMouseDown event handler.
document.onmousedown = function () {
return false;
};
}
else {
//Disable the OnMouseUp event handler.
document.onmouseup = function (e) {
if (e != null && e.type == "mouseup") {
//Check the Mouse Button which is clicked.
if (e.which == 2 || e.which == 3) {
//If the Button is middle or right then disable.
return false;
}
}
};
}
//Disable the Context Menu event.
document.oncontextmenu = function () {
return false;
};
document.onkeydown = ShowKeyCode;
function ShowKeyCode(evt) {
if (evt.keyCode == '123')
return false;
//For F12 Button
}
</script>

Posting Message to iframe using window.postMessage

I am stuck at stupid problem. I am trying to develop a Firefox Extension in which I have a popup panel and in that panel, there is an iframe of a tasks.html File.
I want to postMessage to that iframe on click of a button in my web page(Say webpage interaction with the plugin) but its not working.
Here is the image to the Panel on how it looks.
This is the function, M using to send data to the iframe. The Post Function is called when the button in the webpage is clicked.
function Post() {
var iframe = window.document.getElementById("iframe").contentWindow;
postMessageToWindow(iframe, "Hello");
}
function postMessageToWindow(win, message) {
try {
win.postMessage(message, '*');
return true;
} catch(e) {
return false;
}
}
and In that html page, I have
window.addEventListener('message', function(e) {
var str_data = e.data;
document.getElementById('test').innerHTML = str_data;
});
but nothing gets shown in the test DIV.
Please help me with it. Thanks.
Ignore my message about win.postMessage I didn't know that postMessage was a "native" function. It's cool helping you I learned something.
Anyways yes it would be nice if your code worked on first time. Thanks to some info from Blargh I found your problem.
Find sample_button.appendChild(tasks_popup); and remove that, why were you doing that? Right now its cloning the original object and adding it.
Another thing, why go through postMessage? Instead of postMessage you can simply do tasks_iframe.contentDocument.querySelector('#test').innerHTML = 'why bother with postMessage, just do this? but i fixed postMessage for you too<br>';
Another thing, the interval of 300ms works but its intensive and not the best solution. It will work for now though.
Do you have plans to upload this to addons.mozilla.org? They don't like setting innerHTML, if you plan to release there let me know and I'll show you how to do it without innerHTML.
Also your "Refresh" button in the panel in overlay.xul needs fixing to document.getElementById('tasks-list').contentDocument.location.reload()
in the code you posted, im not seeing the toolbar button get added, its not even in the customize view, did you test your sample code you uploaded?
the addAsTask function is failing hard in your sample code because elements like #sample-button and #TasksPanel don't exist. please make sure your test case works before uploading
box.com/s/hxn16axnxbwc151h92g
the addon doesnt work on install but i see a problem here:
function postMessageToWindow(win, message) {
try {
window.top.postMessage(message, '*');
return true;
} catch(e) {
return false;
}
}
on line3 it says window.top. use win.top. also i dont think u need to use .top. just use win.postMessage
also is postMessage a function in the iframe? because when i look theres no postMessage function in tasks.html

Gray-out the background when popup opens

I call below javascript on click of link/textbox or button.
function OpenPopupLinkRisk(Number)
{
window.open("../PopUp.aspx?id=" + Number, "List", "scrollbars=no,resizable=yes,width=700,height=450");
return false;
}
I donot want user to do anything else until he closes the popup window. So how can I grey background and force user to first close the popup and then do any other activity on application.
Can anyone suggest me how to achieve this ?
Thanks !
First of all, i would really disrecommend using window.open for this unless you really need a new browser popup window. If you want to stick with it persee, then will have to use a timer or something to manually check when the window is closed like:
var popup = window.open('http://www.example.com', 'example', '');
var timer = setInterval(function() {
if(window.closed) {
clearInterval(timer);
alert('Closed alright');
}
}, 100);
Else, check some tutorials on the subject, Modal Popup
First a direct solution to you problem that I wouldn't advice using it an then an approach you should be taking and is better from usability as well as security point of view.
Check whether popup window has closed
// mask your page
mask();
// open popup
var popup = window.open("../PopUp.aspx?id=" + Number);
// check whether it's been closed
function check()
{
if (popup && !popup.closed)
{
setTimeout(check, 1000);
}
// unmask your page
unmask();
}
check();
Modern (and better) alternative
Using window.open is a bad solution because it's a security risk and popup blockers prevent sites to open new windows. It's also considered bad practice.
A much better modern alternative is to display the new page as modal window inside your page directly. This will not open new windows and users stay as they are.
There are tons of javascript plugins for modal windows. Make a Google search.

Categories

Resources