Object.defineProperty not changing property of element Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Detecting an undefined object propertyHow do I detect a click outside an element?How can I merge properties of two JavaScript objects dynamically?How do I check if an element is hidden in jQuery?How to change an element's class with JavaScript?How do I remove a property from a JavaScript object?Sort array of objects by string property valueHow do I remove a particular element from an array in JavaScript?jQuery scroll to elementIterate through object properties
Understanding piped commands in GNU/Linux
What helicopter has the most rotor blades?
The Nth Gryphon Number
Was the pager message from Nick Fury to Captain Marvel unnecessary?
Fit odd number of triplets in a measure?
How to make triangles with rounded sides and corners? (squircle with 3 sides)
Can gravitational waves pass through a black hole?
Getting representations of the Lie group out of representations of its Lie algebra
malloc in main() or malloc in another function: allocating memory for a struct and its members
First paper to introduce the "principal-agent problem"
Flight departed from the gate 5 min before scheduled departure time. Refund options
How to name indistinguishable henchmen in a screenplay?
Short story about astronauts fertilizing soil with their own bodies
How can I prevent/balance waiting and turtling as a response to cooldown mechanics
What does 丫 mean? 丫是什么意思?
Does the universe have a fixed centre of mass?
Inverse square law not accurate for non-point masses?
Marquee sign letters
Why do the Z-fighters hide their power?
3D Masyu - A Die
Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?
Did pre-Columbian Americans know the spherical shape of the Earth?
Can I cut the hair of a conjured korred with a blade made of precious material to harvest that material from the korred?
Did John Wesley plagiarize Matthew Henry...?
Object.defineProperty not changing property of element
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Detecting an undefined object propertyHow do I detect a click outside an element?How can I merge properties of two JavaScript objects dynamically?How do I check if an element is hidden in jQuery?How to change an element's class with JavaScript?How do I remove a property from a JavaScript object?Sort array of objects by string property valueHow do I remove a particular element from an array in JavaScript?jQuery scroll to elementIterate through object properties
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to override the src
property of all iframes in my application so their src
property always gets set to "redirect.html" regardless of what value the HTML tag defines for it.
So far, I have come up with the following, but it doesn't seem to be applying to the DOM element:
<!doctype html>
<html>
<head>
<script>
var propertyDescriptorSrc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "src");
Object.defineProperty(HTMLIFrameElement.prototype, "src",
get: function get_src()
var val = propertyDescriptorSrc.get.call(this);
return "redirect.html";
,
set: function (val)
alert('setting: ' + val);
propertyDescriptorSrc.set.call(this, val);
);
</script>
</head>
<body>
<iframe src="page.html"></iframe>
</body>
</html>
I expected the iframe element in the body to load redirect.html instead of page.html, since I overrided its "getter", but it still loaded page.html.
Is there a way to force this behavior where all iframes by default go to redirect.html instead of whatever is defined in their src
attribute?
(This is just an experimental project)
javascript
|
show 1 more comment
I am trying to override the src
property of all iframes in my application so their src
property always gets set to "redirect.html" regardless of what value the HTML tag defines for it.
So far, I have come up with the following, but it doesn't seem to be applying to the DOM element:
<!doctype html>
<html>
<head>
<script>
var propertyDescriptorSrc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "src");
Object.defineProperty(HTMLIFrameElement.prototype, "src",
get: function get_src()
var val = propertyDescriptorSrc.get.call(this);
return "redirect.html";
,
set: function (val)
alert('setting: ' + val);
propertyDescriptorSrc.set.call(this, val);
);
</script>
</head>
<body>
<iframe src="page.html"></iframe>
</body>
</html>
I expected the iframe element in the body to load redirect.html instead of page.html, since I overrided its "getter", but it still loaded page.html.
Is there a way to force this behavior where all iframes by default go to redirect.html instead of whatever is defined in their src
attribute?
(This is just an experimental project)
javascript
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.
– Bergi
Mar 22 at 14:01
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting thesrc
programmatically.
– Amy
Mar 22 at 14:28
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
1
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace theirsrc
attribute, as your sole answer demonstrates.
– Amy
Mar 22 at 14:37
|
show 1 more comment
I am trying to override the src
property of all iframes in my application so their src
property always gets set to "redirect.html" regardless of what value the HTML tag defines for it.
So far, I have come up with the following, but it doesn't seem to be applying to the DOM element:
<!doctype html>
<html>
<head>
<script>
var propertyDescriptorSrc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "src");
Object.defineProperty(HTMLIFrameElement.prototype, "src",
get: function get_src()
var val = propertyDescriptorSrc.get.call(this);
return "redirect.html";
,
set: function (val)
alert('setting: ' + val);
propertyDescriptorSrc.set.call(this, val);
);
</script>
</head>
<body>
<iframe src="page.html"></iframe>
</body>
</html>
I expected the iframe element in the body to load redirect.html instead of page.html, since I overrided its "getter", but it still loaded page.html.
Is there a way to force this behavior where all iframes by default go to redirect.html instead of whatever is defined in their src
attribute?
(This is just an experimental project)
javascript
I am trying to override the src
property of all iframes in my application so their src
property always gets set to "redirect.html" regardless of what value the HTML tag defines for it.
So far, I have come up with the following, but it doesn't seem to be applying to the DOM element:
<!doctype html>
<html>
<head>
<script>
var propertyDescriptorSrc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "src");
Object.defineProperty(HTMLIFrameElement.prototype, "src",
get: function get_src()
var val = propertyDescriptorSrc.get.call(this);
return "redirect.html";
,
set: function (val)
alert('setting: ' + val);
propertyDescriptorSrc.set.call(this, val);
);
</script>
</head>
<body>
<iframe src="page.html"></iframe>
</body>
</html>
I expected the iframe element in the body to load redirect.html instead of page.html, since I overrided its "getter", but it still loaded page.html.
Is there a way to force this behavior where all iframes by default go to redirect.html instead of whatever is defined in their src
attribute?
(This is just an experimental project)
javascript
javascript
edited Mar 22 at 13:58
DemCodeLines
asked Mar 22 at 13:31
DemCodeLinesDemCodeLines
78242956
78242956
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.
– Bergi
Mar 22 at 14:01
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting thesrc
programmatically.
– Amy
Mar 22 at 14:28
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
1
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace theirsrc
attribute, as your sole answer demonstrates.
– Amy
Mar 22 at 14:37
|
show 1 more comment
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.
– Bergi
Mar 22 at 14:01
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting thesrc
programmatically.
– Amy
Mar 22 at 14:28
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
1
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace theirsrc
attribute, as your sole answer demonstrates.
– Amy
Mar 22 at 14:37
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.– Bergi
Mar 22 at 14:01
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.– Bergi
Mar 22 at 14:01
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.
document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting the src
programmatically.– Amy
Mar 22 at 14:28
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.
document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting the src
programmatically.– Amy
Mar 22 at 14:28
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
1
1
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace their
src
attribute, as your sole answer demonstrates.– Amy
Mar 22 at 14:37
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace their
src
attribute, as your sole answer demonstrates.– Amy
Mar 22 at 14:37
|
show 1 more comment
1 Answer
1
active
oldest
votes
Before it starts javascript, the DOM tree is already parsed and contains all iframes together with its src, according to the Critical Rendering Path.
The only way to do this is by using javascript to redefine the src attributes of the individual iframe node. For example, as below.
all iframes are set to redirect.html:
<!doctype html>
<html>
<head>
</head>
<body>
<iframe src="page.html"></iframe>
<iframe src="page2.html"></iframe>
<script>
( function()
var lng = document.getElementsByTagName('iframe').length;
for (var i=0; i<lng;i++)
document.getElementsByTagName('iframe')[i].src="redirect.html";
)();
</script>
</body>
</html>
According to the suggestion, @Aaron Digulla gives a more readable form of function.
It seems that the search algorithms of the DOM tree are so efficient today that the argument is the readability of the record, not the efficiency.
(function()
var frames = document.getElementsByTagName('iframe');
for (var i=0; i<frames.length;i++)
frames[i].src="redirect.html";
)();
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.
– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55300750%2fobject-defineproperty-not-changing-property-of-element%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Before it starts javascript, the DOM tree is already parsed and contains all iframes together with its src, according to the Critical Rendering Path.
The only way to do this is by using javascript to redefine the src attributes of the individual iframe node. For example, as below.
all iframes are set to redirect.html:
<!doctype html>
<html>
<head>
</head>
<body>
<iframe src="page.html"></iframe>
<iframe src="page2.html"></iframe>
<script>
( function()
var lng = document.getElementsByTagName('iframe').length;
for (var i=0; i<lng;i++)
document.getElementsByTagName('iframe')[i].src="redirect.html";
)();
</script>
</body>
</html>
According to the suggestion, @Aaron Digulla gives a more readable form of function.
It seems that the search algorithms of the DOM tree are so efficient today that the argument is the readability of the record, not the efficiency.
(function()
var frames = document.getElementsByTagName('iframe');
for (var i=0; i<frames.length;i++)
frames[i].src="redirect.html";
)();
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.
– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
|
show 1 more comment
Before it starts javascript, the DOM tree is already parsed and contains all iframes together with its src, according to the Critical Rendering Path.
The only way to do this is by using javascript to redefine the src attributes of the individual iframe node. For example, as below.
all iframes are set to redirect.html:
<!doctype html>
<html>
<head>
</head>
<body>
<iframe src="page.html"></iframe>
<iframe src="page2.html"></iframe>
<script>
( function()
var lng = document.getElementsByTagName('iframe').length;
for (var i=0; i<lng;i++)
document.getElementsByTagName('iframe')[i].src="redirect.html";
)();
</script>
</body>
</html>
According to the suggestion, @Aaron Digulla gives a more readable form of function.
It seems that the search algorithms of the DOM tree are so efficient today that the argument is the readability of the record, not the efficiency.
(function()
var frames = document.getElementsByTagName('iframe');
for (var i=0; i<frames.length;i++)
frames[i].src="redirect.html";
)();
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.
– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
|
show 1 more comment
Before it starts javascript, the DOM tree is already parsed and contains all iframes together with its src, according to the Critical Rendering Path.
The only way to do this is by using javascript to redefine the src attributes of the individual iframe node. For example, as below.
all iframes are set to redirect.html:
<!doctype html>
<html>
<head>
</head>
<body>
<iframe src="page.html"></iframe>
<iframe src="page2.html"></iframe>
<script>
( function()
var lng = document.getElementsByTagName('iframe').length;
for (var i=0; i<lng;i++)
document.getElementsByTagName('iframe')[i].src="redirect.html";
)();
</script>
</body>
</html>
According to the suggestion, @Aaron Digulla gives a more readable form of function.
It seems that the search algorithms of the DOM tree are so efficient today that the argument is the readability of the record, not the efficiency.
(function()
var frames = document.getElementsByTagName('iframe');
for (var i=0; i<frames.length;i++)
frames[i].src="redirect.html";
)();
Before it starts javascript, the DOM tree is already parsed and contains all iframes together with its src, according to the Critical Rendering Path.
The only way to do this is by using javascript to redefine the src attributes of the individual iframe node. For example, as below.
all iframes are set to redirect.html:
<!doctype html>
<html>
<head>
</head>
<body>
<iframe src="page.html"></iframe>
<iframe src="page2.html"></iframe>
<script>
( function()
var lng = document.getElementsByTagName('iframe').length;
for (var i=0; i<lng;i++)
document.getElementsByTagName('iframe')[i].src="redirect.html";
)();
</script>
</body>
</html>
According to the suggestion, @Aaron Digulla gives a more readable form of function.
It seems that the search algorithms of the DOM tree are so efficient today that the argument is the readability of the record, not the efficiency.
(function()
var frames = document.getElementsByTagName('iframe');
for (var i=0; i<frames.length;i++)
frames[i].src="redirect.html";
)();
edited Mar 22 at 17:55
answered Mar 22 at 14:29
Slawomir DziubaSlawomir Dziuba
3106
3106
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.
– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
|
show 1 more comment
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.
– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.– Aaron Digulla
Mar 22 at 15:19
document.getElementsByTagName
is an expensive call. You should assign it to a local array and then iterate over this array instead of calling this many times.– Aaron Digulla
Mar 22 at 15:19
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
@Aarin Digulla This is just a quick example. You're absolutely right.
– Slawomir Dziuba
Mar 22 at 15:30
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
Keep in mind that a lot of people will just copy&paste your example.
– Aaron Digulla
Mar 22 at 15:54
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
@Aarin Digulla You're right. However, after profiling both versions, it appears that the presented solution is faster by 49 ms than the solution with the assignment of an array for 10,000 iterations in the FF browser. It's within the limits of statistical error. You can check the profile because maybe I've made an error somewhere.
– Slawomir Dziuba
Mar 22 at 16:26
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
I didn't expect these results. How big was the DOM?
– Aaron Digulla
Mar 25 at 9:31
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55300750%2fobject-defineproperty-not-changing-property-of-element%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
HTMLIFrameElement.prototype
is not used by the browser when evaluating an iframe. It is only the DOM interface from JavaScript to the actual data. Adding (or overwriting) a getter doesn't affect the internal browser data.– Bergi
Mar 22 at 14:01
What is it using then? Can that be modified in this manner?
– DemCodeLines
Mar 22 at 14:08
I think it will "sort-of" work if you programmatically create the iframe after overriding its property, e.g.
document.createElement('iframe')
. I don't think it will work on iframes already part of the DOM. Run your code in your browsers console, then create an iframe. You can test it by setting thesrc
programmatically.– Amy
Mar 22 at 14:28
@Amy is there a way to apply it to dom elements? Or maybe first define the property for iframe so when the dom is parsed, it uses the new property of src and ignores the one that is specific there?
– DemCodeLines
Mar 22 at 14:35
1
Aside from using JS to find, duplicate, and replace the DOM elements, I don't think so. But if you're going to do that, it's easier to simply find those elements and replace their
src
attribute, as your sole answer demonstrates.– Amy
Mar 22 at 14:37