Forum Moderators: open
User visits site A, clicks on link similar to
<a href="#" onclick=openWindow('target_value'); >
function openWindow(my_target) {
target_url = http://www.example.com/my_target
my_window = window.open (target_url)
my_window.focus()
return false;
}
The target is located on site B
This works as intended in FF and Chrome, but IE throws up a blocked popup exception. In order to still show the new page to the user, I modified the last few lines of my code to this:
if (my_window == null) {
document.location = target_url;
return true;
} else {
my_window.focus()
return false;
}
Is there any way that a new window can be opened in IE without the user having to make an exception in their popup blocker?
The lightbox trick seems to get around this as it writes to a div on the page, not a new window.
But bit of advice, don't do this,
<a href="#" onclick=openWindow('target_value'); >
do this.
<a href="http://www.example.com/my_target" target="_blank" onclick="return openWindow('target_value');">
You are already returning false from the openWindow function, use it to stop the link from performing it's "natural action." This way, if JS is disabled, it will still make the content accessible, but won't navigate to the href if JS is enabled. Plus it will stop the ever annoying "scroll to the top" (#) if the link is in the middle of the page.
There will be multiple "Site A" - The idea is to allow their webmasters to grab an external .js file with the window.open() function from my Site B and to make it more or less "idiot proof" for them to link to specific functionality on Site B depending on the target value.
The example above was simplified a bit. Since I depend on the ability of other webmasters to follow instructions, I'd like to keep things as simple as possible. I'm stille debating whether it would be feasible to enable this for visitors that do not have js enabled.
The non-js url to point to would then probably become:
http://www.example.com/handler/site_a/target_value
or
http://www.example.com/handler?q1=site_a&q2=target_value
I guess you already see where I'm going with this, in relation with potential SE penalties...
Added: before people make the wrong assumption, the functionality is intended to let our clients use us as an intermediary to provide a service to their customers. This is something that we already do, except only when their customers visit our site directly.