I want to disable the href link in this frame html file . I am able to get the element from other html file but I am not able to set attr or onclick prevent default.
<a id="StatusLink" href="/StatusFrame.html" target="detail"><i class="demo-icon icon-chart-line fa-fw"></i> System Status<span class="demo-icon icon-right-open-1"></span></a>
top.window.frames[1].document.getElementById("StatusLink")
top.window.frames[1].document.getElementById("StatusLink").attr("href", "http://the.new.url");
TypeError: top.window.frames[1].document.getElementById(...).attr is not a function(…)
Thanks, Madhav
attr()
is a jQuery method and you have a plain DOM element, so use Element.setAttribute()
:
top.window.frames[1].document.getElementById("StatusLink").setAttribute("href", "http://the.new.url");
The above will work but it's more appropriate to set the property directly instead of through the attribute, so I would use:
top.window.frames[1].document.getElementById("StatusLink").href = "http://the.new.url";
If you are trying to disable the href then you can add a click handler to prevent default, and leave the href as is:
top.window.frames[1].document.getElementById("StatusLink").onclick = function(e){
e.preventDefault();
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.