Solved

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

Posted on 2014-12-11
10
2,252 Views
Last Modified: 2014-12-12
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.
0
Comment
Question by:JavierVera
  • 5
  • 4
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40495227
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
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 50 total points
ID: 40495229
If the browser is smart, it will block your efforts because it should never allow a new window to open without direct user intervention.
0
 
LVL 1

Author Comment

by:JavierVera
ID: 40495232
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  ? :)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 58

Expert Comment

by:Gary
ID: 40495236
Look at this fiddle
http://jsfiddle.net/GaryC123/L0y59q9w/

A simple window.open for Google and works fine
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 450 total points
ID: 40495237
Your code would become

$(document).ready(function() {
	window.open($("#redirect").attr("href"));
});

Open in new window


And in action
http://jsfiddle.net/GaryC123/L0y59q9w/1/
0
 
LVL 1

Author Comment

by:JavierVera
ID: 40495239
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

0
 
LVL 58

Expert Comment

by:Gary
ID: 40495246
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.
0
 
LVL 1

Author Comment

by:JavierVera
ID: 40495251
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!
0
 
LVL 58

Accepted Solution

by:
Gary earned 450 total points
ID: 40495252
How about using an iframe in the page?
As you are using jQuery look at a modal popup
0
 
LVL 1

Author Closing Comment

by:JavierVera
ID: 40496039
thanks for the time
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question