?
Solved

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

Posted on 2014-12-11
10
Medium Priority
?
2,831 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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 1350 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 1350 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
Suggested Courses

801 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