/    Sign up×
Community /Pin to ProfileBookmark

Detecting when a user opens a new window & getting the url of that window

Hey everyone. I’ve searched around google for a couple days trying to solve this problem but basically I need to be able to detect when a user navigates clicks a link that opens a new window (Specifically from a flash .swf) I also need to be able to determine what the url of that navigation was so I can display it on the page that the click was made. although there are dozens of different javascript, nothing seems to be able to do what i would like.

I’m able to do it by writing an activex control and placing it on the page and then taking advantage of NewWindow3 event of the SHDocVw.InternetExplorer class but activex really isn’t an option for me.

I was wondering if anyone here with more JS experience might have some suggestions. Also if anyone can think of a way to do this with ASP, that would be acceptable as well.

Thanks in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienMay 22.2007 — Do you have control of the code in the page that gets opened in the new window? Or are you looking for, say, a link to google?
Copy linkTweet thisAlerts:
@mithrandiir42authorMay 22.2007 — Hi, thanks for the reply. the only thing i have control over is the page where the link or flash .swf is displayed. but they could click to any destination.
Copy linkTweet thisAlerts:
@toicontienMay 23.2007 — Hm. Well, how about this, and this will only work for HTML links. Links in flash... I dunno.
function attachLinkClickFns() {
var links = [];
if (document.getElementsByTagName) {
links = document.getElementsByTagName('a');
for (var i = 0, end = links.length; i < end; i++) {
if (links[i].target !== '') {
links[i].onclick = function() {
newWindowOpened(this.href);
return true;
};
}
}
}
}


function newWindowOpened(url) {
var displayURLId = 'showURL';
if (document.getElementBId) {
document.getElementBId(displayURLId).innerHTML = url;
}
}


window.onload = function() {
attachLinkClickFns();
};


If you can somehow call the newWindowOpened() JavaScript function from inside the Flash object, then you can make this work in flash too. All you'll need on your page to show the URL is this snippet of HTML:
[code=html]<div id="showURL"></div>[/code]

Any time you have a link like this:
[code=html]<a href="..." target="_blank">...</a>[/code]
The URL will be shown. That is, any time the link tag has a target set, the URL will display on the page.
Copy linkTweet thisAlerts:
@mithrandiir42authorMay 24.2007 — Thanks again for your reply. This looks like it should work for the href links on the page... not sure what to do about links from the swfs though.
×

Success!

Help @mithrandiir42 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...