I have been trying to get this exit pop to work. So far I can get it to work on a Mac in FF, Chrome and Safari, but struggling with IE, FF, Chrome for Windows. These are two snippets that I have tried so far:
<script language=javascript>
function thankYou(){
var win=window.open("[url.com]", "_blank", "left=20,top=20,width=500,height=500,scrollbars=1"); win.focus(); }
</script>
<body onUnload="thankYou()">
and
<SCRIPT>
function thankYou() {
var ConfirmStatus = confirm("We would love to receive your feedback on your experience of this page. Would you like to complete our short survey?");
if (ConfirmStatus == true) {
window.open("[url]", "win", "left=20,top=20,width=500,height=500,scrollbars=1");
} else {
window.close();
}
}
window.onunload=thankYou;
</SCRIPT>
Not sure how to get it functioning on Windows. Thanks in advance!
change:
<body onUnload="thankYou()">
to:
<body onBeforeUnload="thankYou()">
and....
change:
window.onunload=thankYou;
to:
window.onbeforeunload=thankYou;
Related
I want to print the page on load in both Windows and Andriod using any browser including google chrome.
I have tried to print on crome in Andriod phone using window.print() but it was giving error,
<script type="text/javascript">
setTimeout(function () {
if (typeof(window.print) != 'undefined') {
window.print();
window.close();
}
}, 1500);
</script>
So I tried some help from google cloud print and what I found is that, it's been deprecated since 31th Dec 2020.
Here is my code for that,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
setTimeout(function () {
if (isAndroid) {
// https://developers.google.com/cloud-print/docs/gadget
var gadget = new cloudprint.Gadget();
gadget.setPrintDocument("url", $('title').html(), window.location.href, "utf-8");
gadget.openPrintDialog();
} else {
if (typeof(window.print) != 'undefined') {
window.print();
window.close();
}
}
}, 1500);
</script>
Can anyone help me in this.
I want to print the URL on load in both Windows and in Andriod.
I implemented as follow:
Added iframe element to page
<iframe id="print-frame" class="print-frame" title="Print" src="https://www.w3schools.com" onload="print"></iframe>
print-frame {display: none}
function print() {
var frame = document.getElementById('print-frame');
if (!frame) return;
var frameWindow = frame.contentWindow;
if (!frameWindow) return;
frameWindow.print();
}
iframe is hidden but onload it opens print dialog. On windows it's enough for printing.
for android I use PaperCut https://www.papercut.com/products/free-software/mobility-print/
Install server part on PC where printers are connected, share printers in admin web UI.
On Android install MobilityPrint app, turn on Print service 'Mobility Print'
then in Chrome browser select Share->Print and select any MobilityPrint service printer
I know this has been covered extensively as separate issues; I've tried copying verified answers, but I'm having trouble homologating Javascript conditional statements and a link URL change.
Essentially, what I need to do is detect mobile users and change a conference call URL to a tel link. I've been using if (screen.width <=699) { as the condition and it works on redirects. Here's what I've tried:
<script type="text/javascript">
<!--
var call=document.getElementByID('phone');
if (screen.width <= 699) {
call.write('<a href="tel:!PHONENUMBER!">');
else
call.write('<a href="!URL!" target="blank">);
}
//--!>
</script>
</head><body>
...
...
I've also tried these with corresponding else statements to no avail:
no var and document.getElementByID('phone').write
onclick = function() { window.location.href ='tel:!PHONENUMBER!};.
call.src.replace('tel:!PHONENUMBER!');
call.setAttribute("href",'tel:!PHONENUMBER!');
I apologize if this is a super basic issue - I'm still learning Javascript. Thank you in advance.
Will
You need to either wait for the page to finish loading before you execute your JavaScript or move your script block to the bottom of the HTML.
If you want to wait for the page to finish loading, then wrap your code in the following:
window.onload = function () {
// your code goes here
}
Figured it out with help from #sepbot.
<body onload="mobileURL()">
<div id="phone"></div>
<script type="text/javascript">
function mobileURL() {
var a = document.createElement("a");
a.innerHTML="!LINKTEXT!";
var myPhone = document.getElementById('phone');
if (screen.width <= 699) {
a.setAttribute('href', '!TELEPHONE!');
myPhone.appendChild(a);
} else {
a.setAttribute('href', '!URL!');
myPhone.appendChild(a);
}
}
</script>
I am trying to activate full screen mode using Javascript but it is not working.
Please note that console logs inside the function (on line 4 and 11) are printing correct values but full screen mode is not appearing.
what might be the issue? Here's my code.
function fullscreen()
{
var _element = document.getElementById('BookMainDiv');
console.log(_element);
if (_element.mozRequestFullScreen)
{
_element.mozRequestFullScreen();
}
else if(_element.webkitRequestFullScreen)
{
console.log("aaa");
_element.webkitRequestFullScreen();
}
}
HTML
<body>
<div id="BookMainDiv" style="width:500px;height:500px;background-color:yellow">
</div>
<input type="button" style="height:20%;width:20%" onclick="fullscreen()">
</body>
p.s. I am using chrome 31 on windows 8
This should work..
<html>
<head>
<script>
function fullscreen()
{
var fullscrn = document.getElementById("BookMainDiv");
req= fullscrn.requestFullScreen || fullscrn.webkitRequestFullScreen || fullscrn.mozRequestFullScreen;
req.call(fullscrn);
}
</script>
</head>
<body>
<div id="BookMainDiv" style="width:500px;height:500px;background-color:yellow">
</div>
<input type="button" style="height:20%;width:20%" onclick="fullscreen()">
</body>
</html>
P.S:Your code is working fine in my system , (yes, browser is chrome itself)
It happens that the requesFullScreen (webkitRequestFullScreen) does not work in Chrome when developper tools are open and you have break points in the javascript!
Close it and you will see it will work!
----------------------------- EDITED ------------------
Be sure your document declaration is this one:
<!DOCTYPE html>
And try this code :
function FullScreen() {
var element = document.getElementById("BookMainDiv");
if (element.requestFullScreen) {
element.requestFullScreen();
}
if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
}
}
<script>
function Bookmark() {
alert(navigator.userAgent);
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(location.href, document.title, "");
}
else if (window.external) { // IE Favorite
window.external.AddFavorite(location.href, document.title);
}
else if (window.opera && window.print) {
alert("ASAS");
var e = document.createElement('a');
e.setAttribute('href', location.href);
e.setAttribute('title', document.title);
e.setAttribute('rel', 'sidebar');
e.click();
}
}
</script>
Bookmark
I has a script to let user click to bookmark the page. It work ok in IE, but it not work in Firefox24.0 version. It show me error window.sidebar.addPanel is not a function. Any one has idea whats go wrong for the above code. Please help!!! Brilliant thanks.
addPanel was removed from Firefox since v. 23. But you can use markup instead:
Bookmark me
Actually two questions:
First One: Is there anyway to start the browser on a specific URL(instead of about:blank) (I want to have a history length of 0 when starting on that URL?)
Second One:
I believe this is related to the above question
On the page I have the following:
<script type="text/javascript">
function backAway(){
if (navigator.appName == 'Microsoft Internet Explorer'){
// under ie
i = 0;
} else {
//firefox, chrome, etc..
i = 1;
}
if (history.length>i)
{
// there appear to be items in the history property
// this seems to happen with Firefox
// If refferer exists, then do a back
if (document.refferer){
history.back();
} else {
window.close();
}
} else {
window.close();
}
return false;
}
</script>
Cancel
python selenium stuff here:
driver = webdriver.Firefox()
driver.get(urlOAuth)
declineButtons = driver.find_elements_by_id('declineButton'])
declineButtons[0].click()
It successfully finds the declineButton, but the click appears to have no effect.
The page appears to function correctly when not using selenium.
Any thoughts? Suggestions? Questions?
There is no Conecept Of Array here
Use the Statement driver.findElement(By.id("declineButton")).click() I am sure this will work.