Solved

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

Posted on 2013-01-23
11
370 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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

21 Experts available now in Live!

Get 1:1 Help Now