--Boundary-00=_zBP3+PK99ue4g2+ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline This patch that tries to fix Bug #58650: http://bugs.kde.org/show_bug.cgi?id=58650 If a JavaScript form.submit() is called and the form has a non-existent target specified, a new browser window pops up. This trick to get around popup blockers is used on http://sharereactor.com. The patch tries to check if a frame with the target name exists. If not, it either blocks it (deny/smart policy) or asks. I've put it into ecma/kjs_html to make sure it's only checked if the form is submitted via JS. I tested this with a few testcases and it works for me. I wasn't sure if a frame is allowed to be replaced in a different frameset. That check might need to be added. regards, Ralf --Boundary-00=_zBP3+PK99ue4g2+ Content-Type: text/x-diff; charset="us-ascii"; name="form_popup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="form_popup.patch" Index: kjs_html.cpp =================================================================== RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v retrieving revision 1.245 diff -u -p -r1.245 kjs_html.cpp --- kjs_html.cpp 23 Apr 2003 17:55:46 -0000 1.245 +++ kjs_html.cpp 3 Jun 2003 18:54:19 -0000 @@ -54,6 +54,10 @@ #include "rendering/render_object.h" #include "rendering/render_root.h" +#include "kmessagebox.h" +#include +#include + #include using namespace KJS; @@ -2108,7 +2112,44 @@ Value KJS::HTMLElementFunction::tryCall( case ID_FORM: { DOM::HTMLFormElement form = element; if (id == KJS::HTMLElement::FormSubmit) { - form.submit(); + + DOM::HTMLDocument doc = element.ownerDocument(); + KHTMLView *view = static_cast(doc.handle())->view(); + bool ask = false; + + if ( !(view && view->part() && view->part()->parentPart()) ) { + // this page is not within a frameset, new window will open + ask = true; + } else { + if( !view->part()->parentPart()->frameExists( form.target().string() ) ) { + // no frame with target name exists, new window will open + ask = true; + } else { + // there is a frame with the target name, allow submit + form.submit(); + } + } + + if ( ask ) { + KHTMLSettings::KJSWindowOpenPolicy policy = + view->part()->settings()->windowOpenPolicy(view->part()->url().host()); + + if ( policy == KHTMLSettings::KJSWindowOpenAsk ) { + if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ? + i18n( "This site is requesting to open up a new browser " + "window via JavaScript.\n" + "Do you want to allow this?" ) : + i18n( "This site is requesting to open

%1

in a new browser window via JavaScript.
" + "Do you want to allow this?
").arg(KStringHandler::csqueeze(form.action().string(), 100)), + i18n( "Confirmation: JavaScript Popup" ) ) == KMessageBox::Yes ) + form.submit(); + } + } + + // this is a form without a target, allow submit + if(form.target().isEmpty() ) + form.submit(); + return Undefined(); } else if (id == KJS::HTMLElement::FormReset) { --Boundary-00=_zBP3+PK99ue4g2+--