Make popup on load working - javascript

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();
})

Related

onclick window will not trigger if a specific cookie exits

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>

Auto Click on hyperlink

I would like to a HTML code with the following functions if you guys can help , please.
Once the page loads, after 1 second to auto click on a hyperlinked text , how do I do this ? For the new website to be opened in the same window.
I have this code but this one is sending me to a new window and the pop up is blocking - not good
<!DOCTYPE html>
<html>
<body>
<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click();
}
</script>
</head>
<body onload="setTimeout('autoClick();',700);">
<a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
</body>
</body>
</html>
Thanks
Instead of using <a href=> you should try just setting the variable window.location.href. So your code should look something like this:
<body onload="window.location.href='http://www.google.com',700);">
https://www.w3schools.com/howto/howto_js_redirect_webpage.asp
Let me preface this by saying this is extremely questionable when it comes to web design, and generally regarded as a shady or bad practice. That said:
$(window).on('load', function(){
window.location = 'http://example.com'
});
OR (vanilla JS)
window.onload = function(){ window.location = 'http://example.com' };
Again, be careful with this. If you want to do something like this, you need a pretty good reason why.
Possible duplicates:
Redirect from an HTML page
HTML redirect on page load

Android sending sms onload JS

Hello i use this script on my landing pages, but the user needs to click a button for it to work.
<a onclick="ClickTrack('click5')" href="smsto:NR?body=TEXT" class="btn_2" >
<strong><span class="cta-clik">Click to send sms</span></strong>
</a>
Does anybody know how to make it work without button click but when website Loads?
Personally I dislike the inline bindings but you could try putting it on your body tag
<body onload="ClickTrack('click5')">
If possible bind in your logic or just call it like #randy was saying.
For the redirect part, you can make a function like this:
function redirect()
{
window.location.href = "smsto:NR?body=TEXT"
}
If you use JQuery, you could use document.ready inside your script file:
$('document').ready(funtion(){
redirect();
});
If you don't, include the script in the bottom of your page like this:
<body>
<!-- content here -->
<script>
document.addEventListener("DOMContentLoaded", function(event) {
redirect();
});
</script>
</body>

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>

simple javascript not working

I've been having trouble with javascript. I don't think its my code but possible some outside factor. I've tried the following code on chrome and firefox and I can't get the alert to pop up. Nothing happens when I click the link. The code below is obviously not on my site, but I'm just using it as an example as to why other parts of my javascript aren't working.
<html>
<head>
<script language="javascript">
function art() {
alert("jdsklfs");
}
</script>
</head>
<body>
<a href='#'>click</a>
</body></html>
Well, try calling it ;~)
function art() {
alert("jdsklfs");
}
window.onload = art; //<= now the function will execute on page load
or provide the href with an id (<a href='#' id='artclick'>click</a>) and assign a click handler to it on load
function art() {
alert("jdsklfs");
}
window.onload = function(){
document.getElementById('artclick').onclick = art;
}
You are not calling the art function.
Simplest, but dirtiest is to have:
click
try adding
onclick="art();"
to your anchor tag
Change the
<a href='#'>click</a>
to
click
art() isn't tied to the link in any discernible way.
Change your a tag to:
click

Categories

Resources