Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have a webpage that has several <div> sections ("navcol" and "maincol"). The "navcol" div contains <object data="mypage.html">. Inside mypage.html there are buttons the
<div>
<object data="mypage.html">
I have a webpage that has several <div> sections ("navcol" and "maincol"). The "navcol" div contains <object data="mypage.html">. Inside mypage.html there are buttons the user can click to select pages to be inserted into "maincol". I need to gain access to the innerHTML of "maincol" in the main page with Javascript, so I can do the insertion (like using an iframe). Can someone put me on the right track?
PS. I am using <object>, because I want to have HTML 4.0 "Strict" and Iframes are not in "Strict", but s are.
<object>
It is easier to deal with JSONP request using $resource.
app = angular.module('myApp', ['ngResource']) app.service('calendarFactory', function ($resource, $q) { return { query: function () { return $resource(URL, { get: { method: 'jsonp' } }); } } }); function Ctrl($scope, calendarFactory) { $scope.eventSource = calendarFactory.query().get(); }
从对象元素的页面中,您可以使用以下方法访问最上面的浏览上下文:
window.top.document
所以你可以尝试:
window.top.document.getElementById('maincol');
毫无疑问,仅在同源政策所施加的限制范围内。
例如
<div id="mailcol">maincol</div> <div id="navcol"> <object data="foo.html"></object> </div>
在 foo.html 中:
<button onclick=" alert(window.top.document.getElementById('mailcol').innerHTML) ">button</button>