[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-01-23
11
Medium Priority
?
402 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

650 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