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
Solved

JavaScript: How can I listen for a popup window and convert the window to a link.

Posted on 2013-01-23
11
384 Views
Last Modified: 2013-01-29
Hi

I would like to listen for somebody clicking on a javascript popup link and convert it to a normal html link so that the main portal navigates to the target.

Is this possible?

NB: I can not use jQuery.
0
Comment
Question by:AdrianSmithUK
11 Comments
 
LVL 17

Expert Comment

by:selvol
ID: 38808975
If you have control of the page it's no problem,
But I am pretty sure you do not control the link on the page.

Please explain your Page/Site/Problem with some more detail.
As it is sort of hard to know what you are asking exactly.


No one Wants you to know which sites they visit when they leave your site.

SElvol
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38808982
Yes. Your question is not clear enough to understand.
0
 

Author Comment

by:AdrianSmithUK
ID: 38808999
I am producing a browser application using Adobe Flash Builder. The problem with the HTML component in Adobe Air is that it can't handle popup windows. I've fixed the target link issue by appending some javascript to the page that removes the target attribute. However, I still have a problem with javascript popups. Therefore, I want to append some javascript to the page I am reviewing that converts any popup windows to standard html links. I am guessing that there will be a method that can listen for the window.popup event and can:

1. listen for the window.popup event
2. get the event object
3. extract the target url

Does that make sense?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38811403
There ia no such thing as a popup event.  There is a click event that fires a link or function that produces the popup.  As the majority of users block popups the function will fail to do anything.  

If you have control of the code used to produce the popup, then change the code to a link.  If you do not have control of the code, then it would require cross-domain scripting to do what you want and that is a security violation in every modern browser and will be blocked.

Cd&
0
 

Author Comment

by:AdrianSmithUK
ID: 38811962
Popup blockers are not an issue. It is an adobe air application.

In adobe air you can append javascript functions to a webpage without invoking any security issues. I do it all the time.

All I am asking is if there is a way of listening for the onclick event so that I can capture the url in the event object as it bubbles through the dom.

Specifically, is there a function that I could add to the code below that would arrest the popup and change the location of the window instead?

<html>
<head>
</head>

<body>

<a href="#" onClick="MM_openBrWindow('http://www.google.co.uk','Fred','width=700,height=500')">click</a>

<script language="JavaScript" type="text/JavaScript">

function MM_openBrWindow(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}

</script>

</body>
</html>

Open in new window

0
 
LVL 17

Assisted Solution

by:selvol
selvol earned 500 total points
ID: 38813045
I think I understand.....
But I am still not clear if you have  control of the  page and how exactly the  page comes into your app.
You say add to the code above I'd try to hijack the java by creating your own  function.
Using the same name thus Nullifying the intended script..

I don't think the first script is needed...

<script type="text/javascript" language="javascript">
function MM_openBrWindow(theURL,winName,features){
  document.location=(theURL);
}
</script>

<html>
<head>
</head>

<body>

<a href="#" onClick="MM_openBrWindow('http://www.google.co.uk','Fred','width=700,height=500')">click</a>

<script language="JavaScript" type="text/JavaScript">

function MM_openBrWindow(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}

</script>
<script type="text/javascript" language="javascript">
function MM_openBrWindow(theURL,winName,features){
  document.location=(theURL);
}
</script>
</body>
</html>

Open in new window

Selvol
0
 

Author Comment

by:AdrianSmithUK
ID: 38813720
Hi Selvol

Thanks for the help but I think more clarification is needed.

I can't change the functions that are already there. All I can do is try to override them in some way.

Adobe Air has a webkit browser object (same as chrome and safari) that you can add to a form so that you can make your own web browser. (You can do the same in Visual Studio but instead you use a IE object instead.)

In Adobe Air web browser applications there is a problem though. When you click on a link with a _blank or _new target or a link with on onclick event the Air application can't create a new instance of itself and so the link doesn't work. You just click on it and nothing happens.

I have fixed the _blank or _new target issue by iterating through the links on the page and removing the target attribute.

Now I have to fix the onclick issue.

It is worth noting that I can append Javascript to the pages but I can't change what is already there. (Not easily anyway)

Instead I was hoping to override any popup windows by:

1. Listening for the onclick event.
2. Detect if the intention is to open a new window.
3. If so arrest that operation and change it to document.location=(theURL) as you mentioned above.

Can you think of a way?

Kind Regards,
0
 

Author Comment

by:AdrianSmithUK
ID: 38813728
PS:

What I am trying to do is to override the code below. Not change it.

<html>
<head>
</head>

<body>

<a href="#" onClick="MM_openBrWindow('http://www.google.co.uk','Fred','width=700,height=500')">click</a>

<script language="JavaScript" type="text/JavaScript">

function MM_openBrWindow(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}

</script>
<script type="text/javascript" language="javascript">
function MM_openBrWindow(theURL,winName,features){
  document.location=(theURL);
}
</script>
</body>
</html>

Open in new window

0
 

Author Comment

by:AdrianSmithUK
ID: 38814557
0
 

Accepted Solution

by:
AdrianSmithUK earned 0 total points
ID: 38814591
In fact, just like this.


<html>
<head>

<script language="JavaScript" type="text/JavaScript">

function MM_openBrWindow(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}

window.open = function(url, name, opts) {
	document.location=(url);
}

</script>

</head>

<body>

<a href="#" onClick="MM_openBrWindow('http://www.google.co.uk','Fred','width=700,height=500')">click</a>

</body>
</html>

Open in new window

0
 

Author Closing Comment

by:AdrianSmithUK
ID: 38830300
I have selected my solution because it is correct.

Please give the 500 points to Selvol for helping me.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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 …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

790 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