How to retrieve the height of the selected HTML element using Golang? - html

I was using goquery to parse HTML and I need to retrieve the height of these HTML elements but goquery doesn't have a jquery like .css() method? How can I achieve something like this?

You can't. Jquery runs in the browser where the HTML document is rendered and dimensions (such as height) are calculated by the browser, and are available to Javascript code.
Note that you can't access the rendered dimensions, because the document is not rendered. This doesn't mean you can't access the static attributes (e.g. height) of the HTML tags, but there is absolutely no guarantee that this value will be the actual height of the element.
Goquery runs outside of your browser, where the HTML document is not rendered, and as such, dimensions are not available.
If you want to do it in Go, the HTML document must transfer this information to your Go app (server) e.g. via an AJAX call, or you must run your Go code in the browser, for which there are gopherjs and the Go web assembly target.

Related

Check if Embedded TikTok content is fully loaded

I'm trying to set the width and height of TikTok's embedded post in my webpage because the default size seems to big.
From the documentation on TikTok's Developer site, we can't manually set the width and height of the embedded content so I'm planning to set its height when the embedded content is fully loaded.
When I inspect the webpage, here are the piece of code generated when the embedded content is not fully loaded yet :
The dynamically generated piece of code is the <iframe> tag (and also many tags inside of it).
And those code change when the iframe is fully loaded, like this :
I already know which tags/elements I should apply CSS to to make the Embedded video smaller, but i don't know how to select the generated element using jQuery.
How can I achieve this?
Note :
"Dynamically generated" code means that i don't write the code myself, but the code generated because i write the embed code.

Using iframe to embed HTML fragment

I am wanting to embed an HTML fragment (a Google Maps div) using an iframe. (It has to be an iframe, because that is the requirement of the WordPress plugin we are using.)
Embedding the entire HTML of the map page is making the google map misbehave. So is it possible (and good practice) to embed a 'page' that is not a complete HTML page - i.e., a 'page' that is just an HTML snippet (in this case, the map div and associate JavaScript)?
An idea is to set the iframe to the appropriate width and height and set the scrolling attribute to "no". I've seen this many times.
Whatever you embed with iframe will be taken as a complete document. Technically, HTML code that consists of only a div element and a script element is not valid, but browsers don’t care: they treat it as if it were a complete HTML document containing those elements in its body.
This answers the question asked, but I presume that you wanted to ask how to extract such elements from a document (dynamically). The answer is that it you would need server-side code that gets a document by URL, parses it, and returns the extracted part. The URL of such a code would then be used in the src attribute of iframe. Generally, such operations may constitute a copyright infringement, if performed without the consent of copyright owner. When using Google Maps for example, you should limit your actions to those permitted by Google.

Direct preloaded HTML content in iframe rather than src

I have HTML content (mostly e-mails) that I would like to display in an archive. Seeing as some of these records contain their own styles, images, and headers, they need to be displayed independently and confined to its container so as not to interfere with the page displaying it. I immediately thought of an iframe.
I have two ways I can do this, both are somewhat indirect. 1) I can draw an iframe that points to about:blank and use Javascript to draw the content into the iframe after the page loads. 2) I can create a secondary PHP page that returns only the content of the e-mail and point the iframe to it as the src attribute. These solutions are simple enough, but I was wondering if there is a more direct way.
I found solutions like these, but they suggest using options 1 or 2 above. The point of this question is: "Is there a more direct way to preload HTML content directly into an iframe than to rely on Javascript or a secondary page?"
Html code as IFRAME source rather than a URL
Specifying content of an iframe instead of the src to a page
I am not sure how much more "direct" you can get than to specify a page in the src attribute of the iframe.
You already link to the only answer that actually works in your question that does not include using a src page or using EMCAScript to draw the iframe content. Remember thought that data urls are still limited in the number of bytes of data they can display in most browsers because there are limits to the length of the data url itself.
I would really suggest that you use the src attribute with a seperate backend script as that will decouple and increase the maintainability of your code as you can develop the scripts responsible for the page itself seperatly from those that show the iframe content.

How to embed a dynamic generated HTML document into HTML document?

I am writing a testing framework for my web app. The case is to test some AJAX methods. While there are some server side errors, the response of AJAX calling is a HTML document log. However, I would like to display the HTML document in the same testing page while the response received. I am afraid I cannot insert the HTML document into a div since it is not html snippet but a complete HTML document. Is there anyway to deal with the problem without server-side effort?
Besides, I have considered about iframe. However, it seems that it only could display a webpage by specifying the url.
Thanks in advance!
Edit
I tested Aaron's second solution. It surprised me that I could insert a complete HTML document into HTML document and keeps its styles.
You have two options:
Create an iframe and load the HTML document into it
Or locate the body element in the result and just add the content of that element to the div next to your test case.
The first one can cause problems with Cross Site Scripting (which you may or may not apply to your case). The second one means you have to merge the styles of the results into your test HTML document or it won't look as you want.

If an <object> plugin fails (ie Flash) have it render some other content?

I have a flash header that I show on one of my customers sites, but instead of creating an entire new website for non-flash, is there a way I can have it render a static image version of the header instead of either redirecting or just not rendering the flash content at all (ie with a FAIL message)?
Maybe something like a noscript for object?
And easy way to do this is to use SWFObject.
http://code.google.com/p/swfobject/
A javascript based solution that allows you to create fallback content.
Just put whatever you need inside of the object element and it'll fallback.