Popup without user action? - javascript

How is this site triggering its popup while bypassing Chrome's pop-up blocker?
http://undertexter.se/
I thought pop-up blockers only allowed window.open if it was triggered by a user action but that's not the case here so how are they doing it?

OUTDATED
Origin resources and fiddles do not work anymore.
I figured out that there is an popup opening in chrome if you visit the Website first time (empty cache) and click somewhere on the document.
After a refresh and a click on it again nothing will happen if cache wasn't removed.
So lets start the game of reverse engineering...
Took the script from
http://undertexter.se/ and startet refuscation.
After a few steps I got the following code and I think this is not planned by browser manufactures to support something like this.
Now I wish you a lot of luck to use that for your own but I think it's evil.
Look on js fiddle for the result:
Its the reverse of:
http://www.wigetmedia.com/tags/undertexter.se.js
http://jsfiddle.net/W9BdS/

Tested on my own server, This opens up http://google.com in a new (standalone) window in Chromium 28 on Ubuntu 12.04. Adblock is active.
<script type="text/javascript">
document.addEventListener('click', function() {
window.open('http://google.com','...','width=1080 height=640')
})
</script>

try this using JQuery
$('#yourCotrolId').on('click', function() {
window.open('yourLink','...','width=1080 height=640')
});

window.open is blocked by modern browsers when called not in a click event handler.
I faced this myself while using Rails' format.js responses and wrote a small plugin that makes showing JS popups as simple as calling window.open():
Popup("<div>Hello world</div>").show('up')

You could use the .trigger method for simulating an user action:
Click
$('a').trigger('click');

.trigger() can not be used to mimc such native browser events, you can use .simulate() from simulate.js to mimic such events.
include simulate.js in your file and use,
$('a').simulate('click');

Related

javascript- window.open in safari and chrome in body?

I am adding the following javascript at runtime to open a new browser window. I know window.open is available in javascript. But it doesn't work for safari and chrome. Is there any other trick or hooking technique to achieve this.
string script= "window.open('http://www.w3schools.com','_blank','toolbar=yes,location=yes,directories=no,status=1,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,left=20,top=20,width=600,height=550');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindowScript", script, true);
Thanks
window.open() most certainly works in Safari and Chrome, I used it today! The demos on the w3Schools site work in Chrome
Try moving the code into a standard in-page <script> block (obviously with the .net stuff removed) to test and see if you get any errors in the console.
It could be that one of the features you are passing as the 3rd argument to .open() is breaking things (like the copyhistory feature - I never saw that before, and it isn't listed in the available options on the w3Schools site)? I have noticed that Chrome tends to ignore the width and open it to whatever size it wants to...
This is because of the popup blocker in the browser. You can use Ajax Modal Popup window instead of Window.Open
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
Another option is Jquery popup
http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
if you still need to use Window.Open then please refer this
Bypass popup blocker on window.open when JQuery event.preventDefault() is set

jQuery .load(): loading a div when click

I would like to achieve that when clicking in an image, in the div where this image is, a div with other content from another .html is loaded, but I can't get it done.
If I do, the following, it works perfectly:
$('#windows_link').click(function(){
$('#apps_container').html("Hi!");
});
But if I do the following, it does not work; it doesn't do anything actually:
$('#windows_link').click(function(){
$('#apps_container').load('windows_apps.html #apps_container');
});
Any help, please?
Thanks a lot in advance!
When you're local any other HTML path is treated as another domain in certain browsers (Chrome is on the list). That means any AJAX request (what .load() does underneath) you attempt will be blocked by the same origin policy.
What you have will likely work fine...just not locally, in Chrome.
You can verify this by testing in another browser like Firefox, or by launching chrome with a command line switch to disable this safety feature (only for testing!, turn it off after):
chrome.exe --disable-web-security
If the first try works correctly, i assume the problem is here
.load('windows_apps.html #apps_container');
When you click the link, do you see a call in your .net panel of firebug or of your debugging console(does the ajax call complete succesfully)?
Is windows_apps.html in the same folder of the page script that calls it?
is there a div called apps_container into that page?

window.open no longer works when called in the onunload event handler in IE9

In my web application, I launch a desktop application using a custom url protocol. For example: "fakeproto://" will launch "fakeproto.exe" on your desktop. If you don't know what I'm talking about, read this: Registering an Application to a URL Protocol
I needed a way, though, to make sure "fakeproto.exe" was installed on the user's PC before attempting to launch. It's a bit of a hack, but I got it to work for all the major browsers. IE presented the most problems and had a unique implementation.
In Javascript, I would first try to load the custom url protocol:
window.open('fakeproto://', '_self');
Before this, I actually defined the following onunload event handler:
window.onunload = function()
{
window.open('help.php', '_self');
}
So if the desktop didn't recognize the custom url protocol, IE would simply leave the current page and go to "webpage cannot be displayed". In this event, the onunload event handler would fire and open help.php instead.
This works great in IE7 & IE8, but once I upgraded to IE9, this no longer works? It goes to "webpage cannot be displayed" instead of help.php.
Using a debugger, the onunload event handler is firing and the code is being executed correctly, but for some reason the window.open call isn't working??? I disabled the pop-up blocker as well, to make sure it wasn't that. No luck.
Anyone have any ideas? Anyone hear of IE9 being more strict with window.open? Anyone know of any alternative solutions to the original problem?
BTW, I can get it to work if I open help.php to a new window.
window.onunload = function()
{
window.open('help.php', '_blank');
}
But this only works if any pop-up blockers are disabled. I would like to avoid using this solution.
Yes, IE9 blocks navigations in the onunload handler.

JavaScript parent page redirection from iframe

I need to implement parent page redirection from iframe. I know that it is impossible to do in different domains due to browsers security.
However I found that links have target attribute and tried to use it in the following way:
someLink
It works fine if I click this link manually, but I couldn't find cross-browser solution to simulate it using JavaScript.
document.getElementById('testParentRedirect').click();
This works fine in IE, however Firefox and Safari don't know click function :).
I tried to work with jQuery, but for some reason they don't simulate click event for links.
(see following post)
I couldn't find any appropriate solution on Stack Overflow.
Maybe someone could help me in it. I will appreciate it. :)
You can do this in javascript to exit a frame:
window.top.location = "http://google.com";
You can try
top.location.replace( "http://google.com" );
in javascript to "escape" from the frame.
Edit: Using replace is slightly nicer, changed my answer to use that.

How-to Make a JS Confirm Below leaving the page function

Google Docs, Gmail etc have this feature where if you try to leave a page that hasn't been saved it pops a dialog box with "confirm, Are you sure you want to navigate away from this page?"
Is there a JQUERY plugin that will allow me to implement this kind of functionality?
Thanks
You need to look at the window.onbeforeunload event, which is not supported in all browser, so don't count on it.
Here's the MS documentation for it - it was originally an IE only event.
window.onbeforeunload; it does appear that there are efforts to Standardize the event between browsers too: http://kenbrowning.blogspot.com/2009/01/using-jquery-to-standardize.html
I just found this which seems to be an elegant solution too: http://www.jonstjohn.com/node/23

Categories