i build a site (in PHP) where the users register and then access to reserved Powerpoint presentations. The owner told me to record the time users spend on viewing presentation, but i don't know how to display and record this kind of data. I think that JS and AJAX could help me, but i don't know what script can i use to do that.
Thank you in advice for your opinions and help.
basically you should trigger a php script when the user closes the powerpoint presentation, and this can be achieved for example opening the presentation in a modal window and force the user to click on a "close" button to terminate the presentation.
Another solution may be to open the presentation in a new window (even if is not so elegant) and use this script to trigger and action when the window onunload event is triggered:
<a>Click me!</a>
window.onclick = function() {
var win = window.open("/");
win.onload = function() {
console.log("onload");
win.onunload = function() {
alert("onunload");
}
}
}
Hope this help.
Related
I have a little application on web that uses JS Alerts. I am planning to use modal pops later, but for the time being, does anyone know how to detect if the user clicked on the "prevent this page from creating additional dialogs" and then fire some js function?
it is indeed possible to detect if prevent additional dialogs has been clicked by working with javascript date
you can try this lines of code
window.nativeAlert = window.alert;
window.alert = function(message) {
var timeBeforeAlert = new Date();
var confirmIfBlocked = nativeAlert(message);
var timeAfterAlert = new Date();
if ((timeAfterAlert - timeBeforeAlert) < 400) {
tellTheUserDialog("you can use a Div to tell the user he has blocked alert");
}
}
if users does not see alert then timeAfterAlert will be almost the same as timeBeforeAlert, i used 400 milliseconds just for reference you can come up with yours
You can't detect it because it is a browser feature which helps the user get rid of indefinite popups. This is particularly useful when your JavaScript code shows popups in a loop.
A good idea is to use modals or plugins like Bootbox to show alerts.
I noticed that if I have a gmail tab open with conversation view on/off, and then I open another tab and change the conversation view setting, my original tab stays in the conversation view state it started in such as when doing new searches etc. and the new tab uses the setting I just changed it to.
This led me to think there might be some JavaScript bookmarklet / favelet / "scriptlet" that could easily let us change the setting for a given gmail tab temporarily without having to go into the settings.
Does anyone know of this already in existence or is anyone able to create it? My thought would be to capture a load of gmail with it on and with it off and do a diff / winmerge on the two to see what's different and take it from there, but I'm hoping someone's already created it =).
I'll look into the gmail js and make a bookmarklet :P
Edit: seems the js is obfuscated A lot, copying the function from the original js is gonna be hard...
I'll check what the html changes are between both views and write a js function myself to apply those changes.
I went and instead made it a bit different, I wrote some js that does actually the thing that you would do yourself(it simulates going to settings and changing them).
I made a jsfiddle with a link that can be dragged into the bookmarks bar:
https://jsfiddle.net/randomengineer/0nc4hajp/4/
The bookmarklet code:
javascript:
window.location.hash = 'settings/general';
a = () => document.querySelector('tbody tr:nth-child(13) input:not(:checked)');
b = setInterval(() => {
if(a() != null) {
clearInterval(b);
a().click();
document.querySelector('[guidedhelpid=save_changes_button]').click();
}
}, 5);
Saved settings are just to reload the JS code in the way you prefer, so you are correct it can be made easy to change. seahorsepip did a good one on it, if you need a custom grease script to install to your chrome i would be glad to help.
Love the solution by seahorsepip. I combined it with the "Shortcut Manager" Chrome extension (http://www.makeuseof.com/tag/shortcut-manager-assign-hotkeys-to-various-browser-actions-chrome/) and now I can toggle with a keyboard shortcut!
New solution for 2019 (see Bookmarklet in JavaScript to toggle Gmail conversation view).
This will toggle the current state On/Off and Save:
window.location.href = "https://mail.google.com"+window.location.pathname+"#settings/general";
setTimeout(function() {
convTogs = document.getElementsByName("bx_vmb");
if (convTogs[0].checked) convTogs[1].click();
else convTogs[0].click();
document.querySelector("[guidedhelpid=save_changes_button]").click();
}, 2000);
(Thanks, #Zenoo!)
Note: If you have multiple Gmail accounts open (like me) this will work in your current window (unlike https://mail.google.com/mail/u/0/#settings/general which will go to your default account)
I'm new to Javascript and to Flash, and I'm developing a browser Flash video recorder.
Right now, when I direct my browser to a certain URL, it asks for permission to access the webcam and starts recording - and streaming to a Red5 server on Ubuntu.
I now need to add a javascript button, which when clicked will start the recording, and when clicked again, will stop it. Can someone tell me how to play the .swf file only when the button is clicked? And how to stop playing it when the button is clicked again?
Thanks.
As Pete said, ExternalInterface is certainly what's needed to make function calls between a SWF and the surrounding HTML page.
You can also use swfobject to do cross-browser compatible SWF embedding/loading into a page dynamically.
I've made a little demo of the two features you're looking for here: http://akineticblog.com/fl/ExtIntDemo/index.html
The AS3 code for this is:
import flash.external.ExternalInterface;
var recording:Boolean = false;
//These are two TextFields instantiated on the stage as visual indicators
recordingTF.visible = false;
notRecordingTF.visible = true;
function recording_toggle():void {
recording = ! recording;
//Your actual record start/stop code would go here//
recordingTF.visible = recording;
notRecordingTF.visible = ! recording;
}
if (ExternalInterface.available) {
//This registers the AS3-side function to the JS-side reference
ExternalInterface.addCallback("recording_toggle", recording_toggle);
}
For the HTML/JS side, you can check the page source of the above link, but the main parts are:
function swf_load() {
swfobject.embedSWF("ExtIntDemo.swf", "flashMovie", "500", "250", "10.1", "swf/expressinstall.swf", flashvars, params, attributes);
};
- to be called when you want to load in the SWF, replacing a div with the id 'flashMovie'.
And:
<button onclick="flashMovie.recording_toggle()">Toggle recording</button>
to send the 'recording_toggle' function call into the SWF itself.
You can use ExternalInterface to communicate between JavaScript and AS3. After that it's just a case of making the button call the AS3 functions to you want to perform.
I have written a script that allows a customer to log in, and download their contract in PDF.
We want the contract PDF to open in a popup, but are experiencing problems with customers who don't understand the basics of web browsers...
Basically, the customer logs in and a link is generated for their contract. The link is bound through jQuery's live event handler, that takes the request, sends it to an AJAX logging function then opens the PDF via window.open.
Since it is a user's action that opens the window, I can only think that because it goes through 2 other functions first, it is making the pop-up blocker kick in.
Does anybody have any better ideas?
My code is all over the place, in differnt namespaces, so I hope you guys can figure it all out:
Generate the link in a call back function, if the customer's credentials are correct:
$("#pdfLinks").prepend("<span><a href='#' id='pdfLink'><img src='img/btnDownloadPdf.png' alt='Downdload PDF' /><br>Download Adobe © PDF<\/a><\/span>");
$("#pdfLink").live('click', function() {
UI.showWorkingDialog();
net.tssol.contract.log(contractId['contract'], "DOWNLOAD_PDF", lead);
});
$("#pdfLinks").prepend("<h5>Adobe PDF<\/h5>");
the tssol.log function:
log: function(contract, method, lead) {
$.post("log.php", { lead: lead,
method: method},
function(log) {
if (log['success'] == true) {
if (method == "DOWNLOAD_PDF") {
// change to window.open for popup
window.open("http://oururl.net/public_html/viewPdf.php?verify=" + contract, '', 'scrollbars=1,menubar=0,height=600,width=800,resizable=1,toolbar=0,location=0,status=0');
Let me know if you guys see any way to make the user experience better.
Thanks
Maybe you can provide a HTML Version of the contract in a popup and add a "Download PDF" Button at the bottom of the popup content?
But in general you shouldnt use popups since they are often blocked by the web browsers and are in users head synced with trash and viagra-advertising.. you know what I mean ;)
I would do a jQuery Lightbox-like popup inside the website with the HTML-Contract, and optionally offer a PDF Download Button!
Have a look at this one: http://fancybox.net/
I have been to some css/html/js discussing board which provide a text box to enter the html and a "Run it!" button to run the html in new pops up window.
I want to make one also, which is easy in jQuery:
function try_show_result() {
var code = $("#try-input").val();
if (code !== "") {
var newwin = window.open('','','');
newwin.opener = null; // 防æ¢ä»£ç 修改主页
newwin.document.write(code);
newwin.document.close();
}
}
But then I found a security problem: the pops up window has all the abilities of running an arbitrary javascript. So that when another authenticated user runs a given piece of code on the page, then it could stealing cookies or access some url that is only for the specified user only through ajax posts.
Is there an easy way to avoid this?
Update: I added newwin.document.cookie="" before open the window, not sure if this is better.
Is there an easy way to avoid this?
No
That is why Facebook went out and wrote their own version of JavaScript [FBJS].