views:

76

answers:

2

I have written this code for Firefox:

<html><head><title>No</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
</head>
<body>
<form action="javascript:void(alert('Yes'));">
<input type="submit" value="Submit">
</form>
<script>$($('form').submit())</script></body></html>

It correctly displays the alert box. However, when i run this inside an iframe, with this code:

<html><body><iframe src="click.php"></iframe></body></html>

i don't get the alert box, not even if i click the submit button myself. What is going on exactly? The same code works in Chromium

A: 

It looks like it's a problem with FF4 so I'll discuss it on their bugzilla if it's really their fault. I have modified the source so I'm not even sure it is a bug...

BruceBerry
my bug, my fault :-/
BruceBerry
+1  A: 

Well, don't do that then!

It doesn't make any sense to submit a form to a javascript: URL. Use a submit event handler to pick up the form submission and execute script, eg using jQuery:

$('#someform').submit(function() {
    alert('Yes');
    return false;
});

A good rule of thumb about when to use javascript: URLs is: never.

bobince
+1 for rule of thumb
Darko Z
i should have warned that the code didn't necessarily have to make sense :-) this is part of a mozilla mochitest, and i need a way to "click" (or at least, to make firefox follow the paths i want to test) javascript urls automatically
BruceBerry