/    Sign up×
Community /Pin to ProfileBookmark

Open a new window or tab from a pop up help

Hey everyone. I am attempting to have an ajax script pop up a window when the database detects a flag and a user can click one of the links in that pop up. I have been able to get the ajax to pop up the window and i have been able to get the page to load and the pop up close when a link is clicked, but the page that loads is loaded into the page where the ajax created the pop up.

I need to open a new window or tab when a user clicks on a link in the pop up and the pop up close. The new page should not load in the page that generated the pop up.

Here is the code that I am testing with in the pop up window :

[code=php]<script language=”Javascript”>
function toMainWindow(URL){
mainWindow=window.opener;
if (mainWindow == null || mainWindow.closed){
mainWindow = self;
mainWindow.location=URL;
return false;
}
else {
if (mainWindow.exitvariable != null)
{
mainWindow.exitvariable=false;
}
mainWindow.location=URL;
self.close();
}
}
</script>
<script language=”javascript”>
window.location=”conference.php?id=1″;
toMainWindow(“conference.php?id=1”);
self.close();
</script>[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@drewbJan 30.2008 — I'm not sure I completely understand your problem.

Basically what i'm getting is:

You're using AJAX to open a popup when it sees a flag. Inside that popup is a link that the user clicks. When they click this, you're using something like opener.location.href = 'page-here' and the page is loading into the AJAX include page on the screen rather than the main page.

If I was having that problem, I would move the function that actually OPENS the window into the main page (not the ajax page). This way when the flag is seen, Ajax just calls myFunction(); sends all the variables it needs and the MAIN page opens the window. That way when you use opener.location it won't be referencing to the AJAX page as its parent.
Copy linkTweet thisAlerts:
@atokatimauthorJan 31.2008 — No, the page does not load in the ajax area, it loads in the whole page. I do not want it to load in the whole page, I want it to open a new window or new tab after a user clicks a link in the pop up that the ajax creates.
Copy linkTweet thisAlerts:
@drewbJan 31.2008 — No, the page does not load in the ajax area, it loads in the whole page. I do not want it to load in the whole page, I want it to open a new window or new tab after a user clicks a link in the pop up that the ajax creates.[/QUOTE]


Oh, alright then.

Just do a onclick="window.open(...);" on the link -- just make sure to change the name of the new window.

ie.

If the first window is window.open('page.php', '[B]firstWindow[/B]'), '...')

then the second window should be:

window.open('page.php', '[B]secondWindow[/B]', '...')
Copy linkTweet thisAlerts:
@atokatimauthorJan 31.2008 — I tried that, but for some reason, it loads in the same size window as the pop up. When someone is using FF or IE7, I want it to open a new tab in their existing browser when a user clicks on a link in the pop up. If they are using IE6, it should just open a new window the same size as their original window since they don't have tabs.
Copy linkTweet thisAlerts:
@atokatimauthorJan 31.2008 — anyone else know how to do this?
Copy linkTweet thisAlerts:
@atokatimauthorFeb 01.2008 — thanks guys. you are real helpful *sarcasm*
×

Success!

Help @atokatim 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.19,
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,
)...