onclick window will not trigger if a specific cookie exits - javascript

I am not much experience much in javascript. Recently i am trying to learn and implement popunder onclick. Its working perfectly for me but unfortunately every time open a popunder window when i am click the body.
I want to handle something like:
Create a cookie on first time onclick
second time if will be check if cookie exists or not
In this way only one time popunder window will open
Here is the Index code
<html onclick='pop("https://www.google.com",null,{
"point":"uid",
"postback":"doha"
}).under()'>
<script>
window.onerror = function(msg, url, linenumber) {
alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber);
return true;
}
</script>
<script src="POPPage.js"></script>
<script>
pop().postbackHandler({
doha:()=>{
}
})
</script>
POPUnder
</html>
I have other two js file but security reason not sharing this
Can anyone help me to solve this.As i am beginner

Its hard to figure out what it is your trying to do.
But something simple like this would work.
You'll need to replace the alert with whatever it is your trying to run.
<html >
<script src="https://cdn.jsdelivr.net/npm/js-cookie#rc/dist/js.cookie.min.js"></script>
<script src="POPPage.js"></script>
<script>
function mycode() {
if(Cookies.get('nameofcookie') == undefined) {
pop("https://localjs.blogspot.com",null,{
"point":"uid",
"postback":"doha"
}).under()
Cookies.set('nameofcookie', '1')
}
}
pop().postbackHandler({
doha:()=>{
alert("got postback")
}
})
</script>
<body style="background-color:#FF0000" onclick="mycode()">
<p>something</p>
</body>
</html>

Related

Is it possible to set a timeout after a user clicks a HTML Link?

javascript newbie here, but I was wondering if it is possible to set a timeout after a user clicks a HTML Link, now I was wondering this because I am making a simple maths game, and it uses the alert method, which means that once a user clicks the link, the page in which the link is placed, is still visible in the background, which doesn't look very good. I was looking around and found a method called "window.setTimeout" and I was wondering if I could tie that method to the anchor tag in the HTML Code. Thanks :)
My Code: (Note the game isn't finished yet :) )
<html>
<head>
<title>Maths Game 0.1 Beta</title>
<link rel="stylesheet" type="text/css" href="styling.css">
<script type="text/javascript">
var num1 = prompt("What is 2x10?");
if (num1 == '20') {
alert("Nice Job!");
} else {
alert("Oh well, try again.");
}
</script>
</head>
<body>
</body>
</html>
For example, if you have a <a id="foo" href="#"> </a> in your HTML, once could do
document.getElementById("foo").onclick = function() {
setTimeout(function() {
// do stuff
}, 5000); // triggers the callback after 5s
};
Try this:
<html>
<head>
<title> Maths Game 0.1 Beta</title>
</head>
<body>
First Question
<script type="text/javascript">
function question(){
var num1 = prompt("What is 2x10?");
if (num1=='20'){
alert ("Nice Job!");
}
else {alert ("Oh well, try again.");}
}
</script>
</body>
</html>
Fiddle:
http://jsfiddle.net/h7xpxzgg/
If I understand you correctly, you want to actually load a new page and then have the alert pop up, right?
Well, timeouts won't run once the user has left your page.
But there are at least two ways to do what you're asking:
Fake the page.
You can include everything that would be on the "next page" on the current page, but hide it with display:none, and once the user clicks your link, you first make the content of the original page invisible, then make the content of the "next" page visible, and then show the alert.
Pass a value to the next page, and do the alert there.
Since this is all client-side, I suggest using window.location.hash, like
On the current page:
<script>
document.write('Next page');
</script>
On the next page:
<script>
var num1 = window.location.hash.substr(1); // To get rid of the #
if(num1 == '20')
{
alert("Nice Job!");
}
else
{
alert("Oh well, try again.");
}
</script>

how to run function from frame

I have one file (CCPageContainer.swt) that contain number of frames, and each frame call file.
(swt - siebel template file)
this is part of the code with a specific frame:
<HTML dir="swe:dir">
<head>
<title><swe:this property="Title"/></title>
<swe:include file="CCStylesChoice.swt"/>
</head>
<swe:switch>
<swe:frameset htmlAttr="rows='30,30,27,18,42,*,15' border='0' frameborder='No'">
<swe:frame htmlAttr="marginheight='0' marginwidth='0' noresize scrolling='No'">
<swe:include file="CCFrameGoToView.swt"/>
</swe:frame>
</swe:frameset>
</swe:switch>
</HTML>
in the CCFrameGoToView.swt file that has been called I'm trying to call to alert function:
<HTML dir="swe:dir">
<body>
<script language="JScript">
function alert_test()
{
try
{
alert("test");
}
catch (err)
{
//document.write("oops.. an error has occurred");
}
}
</script>
<form name="myForm">
<table>
<tr>
<td>ALERT: <input type="Button" value="alert5" onClick="alert_test();"><br></td>
</tr>
</table>
</form>
<swe:scripts/>
</body>
</html>
the problem is that the alert message doesn't work when I'm pushing the button.
If I’m running only CCFrameGoToView.swt the alert button is working, and i see the message after i push.
but when I'm trying to run it from CCPageContainer.swt, nothing happened when i'm pushing the alert button.
I've also tried window.parent, window.top etc.
please your help. Thanks.
Try hanging your custom function off the top window so the click handler will be able to find its way to it:
top.alert_test = function alert_test()
{
// blah blah blah
}
then:
onClick="top.alert_test();"
As an aside, it feels strange to be directly injecting code into a Siebel Web Template file, so maybe if you tell us a little more about what you're trying to accomplish, we might be able to help you think about a better way to accomplish it.

To auto close a browser window after popping up new email message

I have a simple html that will pop out a new email message for people to send out email.
I need to close a window after the email message popped out. I wish to keep only the email message box.
This is my code, but it's not working:
<html>
<head>
<script type="text/javascript">
function mymessage()
{
location.href = "mailto:abc#com.sg?subject=EmailToEnter";
}
</script>
</head>
<body onload="mymessage()">
<script type='text/javascript'>
settimeout('self.close()',1000);
</script>
</body>
</html>
Try something like this:
function mymessage()
{
var d=document.createElement('A');
d.target='_blank';
d.href='mailto:abc#com.sg?subject=EmailToEnter';
d.click();
}
function closewindow()
{
var d=document.createElement('A');
d.href="javascript:window.open('', '_self', '').close()";
d.click();
}
Or you can use window.open
Also use construction like this
window.setTimeout(function(){closewindow();},1000);
Use this
setTimeout("window.close()", 1000);
BUT
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.
https://developer.mozilla.org/en-US/docs/Web/API/Window.close

Make popup on load working

I'm trying to make a pop up right away when page is loading , but all the browsers are blocking it and don't let the pop up works , this is my code :
<html>
<head>
<script>
function codeAddress() {
javascript:void window.open('http://google.com','1411977082597','width=750,height=550,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');return false;
}
window.onload = codeAddress;
</script>
</head>
<body>
</body>
</html>
There is a solution for that ?
do not need following code
javascript:void
this code use when write javascript on html tags
function codeAddress() {
window.open('http://google.com','1411977082597','width=750,height=550,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
Check your browser javascript enable.
Check your browser allow popup.
Allow popup to work using Javascript is impossible.
You can do it by calling your method in jquery document.ready method. like:
$(document).ready(function(){
codeAddress();
})

Browser close event For Firefox not working

In my application i have to alert user to signout on browser close.
For that i have used the javascript as below
<body scroll="no" onbeforeunload="browerClose()">
<script language="JavaScript" type="text/javascript">
function browerClose()
{
window.alert("Click OK to SignOut");
window.location.href = "http://localhost:8086/egs/ervlet?pri=logOut";
}
this is Working for IE ,but not works for FireFox,
Wats the Problem....Any Suggesstions
Thankxx in Advance,
I would suggest you move the javascript function to the head section of the HTML document. That way it is working for Firefox. Maybe this is because HTML documents are processed in sequential order and you need to define the function before you can use it.
Do something like this:
<head>
<script language="JavaScript" type="text/javascript">
function browerClose()
{
window.alert("Click OK to SignOut");
window.location.href = "http://google.com";
}
</script>
</head>
<body scroll="no" onbeforeunload="browerClose()">
<!-- you code here -->
onbeforeunload event will not work from fire fox version 26 if u used any custom alert message in your application which means you need to perform x operation when closing browser/tab or refreshing page but you put alert message in function which will be called from onbeforeunload then the x (update) operation will not happened.
<html>
<head>
<script>
function unloadfunction() {
alert('test');
// update employee ID in Database
}
</script>
</head>
<body onbeforeunload="unloadfunction();">
</body>
</html>

Categories

Resources