Jump to content

Archived

This topic is now archived and is closed to further replies.

jaymc

self.close firefox

Recommended Posts

Right, Take a look at this link

[code]<A href=http://www.google.com target=iframe "OnClick=javascript: self.close()"><b><u>Close this window</u></b></a>[/code]

That link is in a popup, when someone clicks the link it will load google in the iframe window and close the window

This works fine in IE, however, in firefox, after clicking the link the window closes but google.com does not load in iframe

Obviously a cross browser issue

But, is their a way around this or an alternitive to achieve the same aspect

Thanks

Share this post


Link to post
Share on other sites
And does it work without the target?

Share this post


Link to post
Share on other sites
It needs the target though, as its loading the website inside an iframe

Share this post


Link to post
Share on other sites
I understand, I'm just trying to narrow down the problem.

Share this post


Link to post
Share on other sites
Just imagine a webpage with an iframe on it

You click a link from within that webpage and that brings up a popup

In that popup you have a link with a target to the iframe name, and on clicking that link it also uses an OnClick handler to initiate self.close

It works 100% in IE. In firefox the popup closes but the request is not sent to the target

Share this post


Link to post
Share on other sites
Is it sent anywhere? Does it load in the parent window?  Sounds like FF doesn't know where to find the target frame.

Share this post


Link to post
Share on other sites
Its not sent anywhere, it just doesnt load

Share this post


Link to post
Share on other sites
So the HREF doesn't work at all... I'm confused.

Share this post


Link to post
Share on other sites
<a href='searchresults.php' target='artistnalbums' OnClick="javascript: self.close()"><b><u>Load results in main site</u></b></a>

That works in IE, loads the searchresults.php in artistnalbums iframe and closes the window popup

In firefox it just closes the window popup

Share this post


Link to post
Share on other sites
I think firefox cant pickup the iframe name because its in a popup

I was thinking about using window.location

window.artistnalbums.location

But it cant find that either, so how could i add in the _parent so it knows to look for the main page with the iframe on. Maybe like

window.parent.artistnalbums.location (not sure of syntax)

Share this post


Link to post
Share on other sites
window.parent sounds reasonable... you'll have to see how FF responds.  Try making sure these objects exist as you move down the chain.

Share this post


Link to post
Share on other sites
Ive tried that, it doesnt work. I do recall it saying something about object non existant

I had

window.parent.songs.location

Share this post


Link to post
Share on other sites
Well, post the code or a link to it, and I'll see what I can reproduce on my end.

Share this post


Link to post
Share on other sites
Here is the link code

[code] <a href='searchresults.php?viewresults=yes&criteria=g&searchby=SONGNAME' target='songs' OnClick="javascript: self.close()"><b><u>Load results in main site</u></b></a>[/code]

That code is inside of popup that was loaded from the parent site. The target 'songs' it is referring to is an iframe that is nested in the parent site

Share this post


Link to post
Share on other sites
I understand that... but I can't do anything with just one line of HTML.  I'll need you to make a mock-up of the parent & child windows/frames.

Share this post


Link to post
Share on other sites
paste this into a file called 'mainsite.htm'

[code]<html>
<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function audiosearch(url)
{
newwindow=window.open(url,'name','height=106,width=378');
if (window.focus) {newwindow.focus()}
return false;
}

// -->
</SCRIPT>
</head>
<body>

<a href=# Onclick="javascript:audiosearch('search.htm')"><u>Search</u></a>
<BR><BR>

<iframe src=http://google.co.uk height=400 width=600 name='framer'></iframe>

</body>
</html>[/code]

And this into a file called 'search.htm'

[code]<a href='http://yahoo.com' target='framer' OnClick="javascript: self.close()"><b><u>Load and close</u></b></a>
[/code]

Share this post


Link to post
Share on other sites
Interesting... it looks like the onclick happens before the href, so self.close() closes the pop-up window without executing the href.  If you were to remove the onclick handerl, you'd see that everyone was OK.

Share this post


Link to post
Share on other sites
Yes your right, removing the OnClick handler does allow the content to load in the frame

But, I really do need the OnClick handler to work

So what is the solution or are you all stuck for answers?

Cheers

Share this post


Link to post
Share on other sites
To be honest, I've never encountered this problem before, because I don't use pop-ups ever.  I don't think you can reference this pop-up from the IFRAME, though I don't really know... I'll think about it.

Share this post


Link to post
Share on other sites
This may help with targetting the a frame in the main window then set a small delay before closing the poup window.
I have yet to test this but give it a try..

[code=php:0]
function something() {
    if (opener.frames['yourFrame'].location.href = 'yourpage.html') {
        setTimeout('self.close();', 1000);
    }
}
[/code]

then <a href="#" onclick="something();">Something</a>

Hope that helps,
Tom

Share this post


Link to post
Share on other sites
Yea I tested that and it works fine in FF, Opera and IE6.. You could have less of a delay but you will still need one for fire fox.

Also, this will only work if you are trying to change the location of a frame on the page that you opened the popup from.

Good Luck,
Tom

Share this post


Link to post
Share on other sites
Ive got it working

[b]<a href='searchresults.php?viewresults=yes&criteria=f&searchby=ARTISTNAME' OnClick="opener.frames['artistnalbums'].location.href = 'searchresults.php?viewresults=yes&criteria=f&searchby=ARTISTNAME'; javascript: self.close();" target='artistnalbums'><b><u>Load results in main site</u></b></a>
[/b]

I just had to put the location in an OnClick handler aswell and make sure it was before the self.close

Thanks for the help :D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.