Link to home
Start Free TrialLog in
Avatar of JavierVera
JavierVeraFlag for Peru

asked on

Jquery or Javascript alternative to window.open to get a different target

Hi guys,

Quick, heh.

I am trying to achieve the following:

1- I have a <a> html tag in the jsp page.
2- I want to execute the <a> LIKE with an "onClick" when document ready.

For this i have done the following:


<a id="redirect" href="<%= strToGo %>" target="_blank">aaaa</a>

<script>
$(document).ready(function() {
	
	$(redirect).click();
	
});
</script>

Open in new window


The main purpose for this is to achieve a new window opened when i load the page.
I don't want my url to be blocked by the popup blocker <--

Please any advice would be great.
Avatar of Gary
Gary
Flag of Ireland image

jQuery will emulate the click in so far as any click events/functions attached to the link will be fired
It cannot simulate a person actually clicking the link.

There is no reason a simple window.open shouldn't work
SOLUTION
Avatar of mankowitz
mankowitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JavierVera

ASKER

isn't Jquery or javascript smart enough to validate a sort of valid location for allowing this? actually what i'd like is some sort of advice to achieve the requeriment. So far i have read several guys claiming the same as mankowitz said yet none gave any idea to achieve or solve the issue heh. if the scripts (jquery etc) doesnt provide anything to validate then i guess i am done with this  ? :)
Look at this fiddle
http://jsfiddle.net/GaryC123/L0y59q9w/

A simple window.open for Google and works fine
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Gary, thank you really much for your time.

But i belive the browser blocks the window due the use of 'window.open'.

I have found this post, yet i have no idea how to implement it on the jsp page i am using.

LINK TO CONCURRENT SITE REMOVED

function eventFire(el, etype){
  if (el.fireEvent) {
    el.fireEvent('on' + etype);
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}

Open in new window

The code above will not do what you want if they have all popups blocked - there is nothing you can do in code to override it
The only solution is as I have above and you have to leave it up to the individual user to allow it.
thing is that i do actions in a page very very very different so i must consider use a middle jsp page to do this sort of bridge, yet i hope it will work if not i will explain the workaround when done.
 thank  you!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the time