Solved

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

Posted on 2014-12-11
10
2,027 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:JavierVera
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for the time
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now