This commit is contained in:
MFMF-EGY 2024-11-21 03:44:39 +00:00 committed by GitHub
commit cc2d1797f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 1 deletions

View file

@ -232,7 +232,12 @@ void HTMLParser::run(HTMLTokenizer::StopAtInsertionPoint stop_at_insertion_point
break; break;
} }
} }
// Set element as target element if url fragment matches its id.
auto url_fragment = m_document->url().fragment();
GC::Ptr<DOM::Element> target_element;
if (url_fragment.has_value() && (target_element = m_document->get_element_by_id(url_fragment.value()))){
m_document->set_target_element(target_element);
}
flush_character_insertions(); flush_character_insertions();
} }

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<iframe id="iframe"></iframe>
<script>
const IFRAME_DATA_SRC = `data:text/html,
<p id="foo">This should be green.</p>
<style>%23foo { color: green; }<\/style>#foo`.replace('\n', '');
const iframe = document.getElementById("iframe");
iframe.src = IFRAME_DATA_SRC;
</script>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<link rel="match" href="../expected/iframe-target-element.html" />
<iframe id="iframe"></iframe>
<script>
const IFRAME_DATA_SRC = `data:text/html,
<style>:target { color: green; }<\/style>
<p id="foo">This should be green.</p>#foo`.replace('\n', '');
const iframe = document.getElementById("iframe");
iframe.src = IFRAME_DATA_SRC;
</script>