How to change CSS from a webpage contained in an object tag? (Xhtml, jquery)

I am having a problem with jQuery and XHTML.

Basically, I have an object tag that contains a web page in a data attribute. Now I want that when I click the button, I get this web page and dynamically modify the CSS file that it is currently using.

I tried to get the page using jquery, but all I get is the object itself, not the web page contained in the object.

<div id = "content">
 <object id="contentPageLeft" type="text/html" data="pageReportajes1.xhtml"></object> 
 <object id="contentPageRight" type="text/html" data="pageReportajes2.xhtml"></object>    
</div>

Thank!!:)

+3
source share
3 answers

You can navigate to objects in XHtml pages using the following jQuery snippet:

var contentPageLeft = $('#contentPageLeft')[0].contentDocument;
var itemToEdit = $(contentPageLeft).find('#idOfItemToEdit');

If you want to do the same with an IFrame, use this jQuery piece:

var itemToEdit = $('#contentPageLeft').contents().find('#idOfItemToEdit');

, .

+2

, , - html-? ? ? iFrame.

+1

Just replace <object data=...>with <iframe src=...>. Browsers implement objects such as frames anyway, so a fancy solution does not buy you anything but unnecessary problems.

Also the type is text/htmlnot suitable for XHTML. I bet you are sending HTML files with inconsistent DOCTYPE .

0
source

Source: https://habr.com/ru/post/1743638/


All Articles