[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: [PATCH] JS Form Popups
From: Ralf Hoelzer <ralf () well ! com>
Date: 2003-06-03 19:01:07
[Download RAW message or body]
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
["form_popup.patch" (text/x-diff)]
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 <kstringhandler.h>
+#include <klocale.h>
+
#include <kdebug.h>
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<DOM::DocumentImpl*>(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( "<qt>This site is \
requesting to open<p>%1</p>in a new browser window via JavaScript.<br />" + \
"Do you want to allow \
this?</qt>").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) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic