Solved

JavaScript to open a link in an iframe and PopUp Blockers

Posted on 2004-08-23
5
398 Views
Last Modified: 2008-02-01
Hello,
  I need to open a link in an iframe to do some server validation and redirectthe user to a different location in a new window.
So on click of the submit button, I do some javascript validation and then within the function
document.DataFrame1.location = "action_server_validate.asp?ml_num=" +  d.ml_num.value ;

The action_server_validate generates code to submit a form to an external website with arguments target="_blank"
which is blocked by pop-up blockers.
What are the workarounds...

One way I presume is to substitute the above statement to

window.open("action_server_validate.asp?ml_num=" + d.ml_num.value) ;


anything else...

Thx!
0
Comment
Question by:danths
5 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 300 total points
ID: 11876204
Instead to target the respnse to _blank you could target it to a previously opened popup.
The target name is the second parameter in window.open() call.
Like this:

window.open("", "newWin");
document.DataFrame1.location = "action_server_validate.asp?ml_num=" +  d.ml_num.value ;

Now when your action_server_validate.asp set the targe="newWin" will the popup be populated with the response.



 
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11876916
Is there a reason why target="_blank" is currently being used?  (Is the opening of a new window necessary?)
0
 
LVL 3

Expert Comment

by:Ayesha_K
ID: 11879871
not sure if i'm understanding the problem correctly or not ... but if your browser is not allowing pop-up windows then it wouldn't allow to open you a new one no matter what the name of the window will be ... i mean your page WILL open a new window ... but the user's browser wouldn't let it get displayed ... this is a user's browser setting ... and you can set it  open pop-ups for your own testing purpose but u can't restrict user to view a pop-up even if he has blocked pop-ups.
0
 
LVL 6

Author Comment

by:danths
ID: 11881166
Yes, it is necessary to open the url in a new window.


Ayesha:- I did some basic reading on how these pop-up blockers work, and the difference is that they allow a new window if the user intentionally does an action like click a button or url etc.

Zvonko:- Isn't the net affect of your suggestion the same as
window.open("action_server_validate.asp?ml_num=" + d.ml_num.value) ;
0
 
LVL 15

Assisted Solution

by:Thogek
Thogek earned 200 total points
ID: 11883676
Depending on the popup-blocker softwares involved, most should allow a popup window to appear if the context of the attempt to open the window is a mouse-click event.  I wouldn't guarantee that they all work that way, but by now, I believe that most of 'em do.

> The action_server_validate generates code to submit a form to an external
> website with arguments target="_blank" which is blocked by pop-up blockers.

Can we get a clearer idea as to exactly what action_server_validate is doing?
It *sounds* like action_server_validate is generating an HTML page with an HTML form with target="_blank", and auto-submitting that form via embedded JavaScript (either inline or in an onload handler).  (I'm guessing based on what you've said above; please correct me if this is incorrect.)  If this is so, then the context of the attempt to open the window is a page's onload, *not* a click event, and popup blockers *will* block that.

Have you tried, as you suggested, replacing the initial document.DataFrame1.location assignation with a call to window.open?  (In such a case, the window.open call would be within a click/submit event, and should be allowed by most popup-blockers.)  If so, does that work?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using toggleClass to resize Bootstrap columns 7 44
ASP sending two datas 2 22
ModalPopup  question 22 37
Put POST values into cookies. 14 28
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

685 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