Solved

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

Posted on 2014-12-11
10
2,140 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now