My Chrome extension create a tab using the API
chrome.tabs.create({
'url': other_extension_url
})
The url is the the url of another extension and looks like:
chrome-extension://ext_id_goes_here/url
I would like to change the the title of the newly created tab (document.title).
I tried to do it using content script but as far as I understand there is no way to use content script with url that looks like chrome-extension://
Is there an any other way to do that?
No, there is no way to do that, since security model will not allow you to access other extensions' pages.
The title is set by the document itself, and cannot be modified by tabs API.
Here is one way to do it.
<html>
<head>
<title>My title</title>
</head>
<body style="margin:0;padding:0;overflow:hidden;">
<iframe style="width:100%;height:100%;" src="chrome-extension://extension_id/page.html"></iframe>
</body>
</html>
Note I haven't tried it from within an extension html but it did work from a html file:// opening an extension page in the iframe.
Based on this, you can have a single "wrapper" page that receives the title and the iframe url as a url parameter and updates its DOM to change the title and iframe src.
Related
Is it possible to execute JavaScript in either a preload script or manually targeting an iframe in a webview /The webview is based on chrome , my intuition says it should be possible.
Basically I would like to click a button inside the iframe using:
document.querySelector('button selector').click();
The page looks something like this. (The page is loaded in the webview)
<html>
<body>
<iframe>
<button id="foo">Click</button>
<iframe>
</body>
</html>
I'm working on a private Chrome extension that injects some code into specific websites. I am successful for all except THIS 1 website (which I cant provide you with login access, sorry).
My extension doesn't detect the new(most) of the html content being loaded on the page after navigating through the site only.
For example, when I run document.documentElement.innerHTML; the return string is only the barebones of the page.
The site is using JQuery and I do have JQuery also loaded in my extension, but it still doesn't want to read any elements. The elements do show up in Developer Console but NOT on the Source Page or Frame's Source Page
I really need access to those Elements but I can't figure it out.
Any help is appreciated.
Thanks a bunch.
EDIT: Turns out nothing was working because all the new content was being loaded into an iFrame. Now I have to research iframes :(
This is what the code in the developer's tools looks like
<html>
<iframe src="..." >
#document
<html>
<div id="im trying to get">this content</div>
</html>
</iframe>
</html>
I wan't to make a userscript that will persist with its instance even if I click on a link.
To make a script instance (ie. variables etc) persist, I need to have the page I'm broswing in iframe, which is a child of the window where script is running. And also, parents document location must be same as the inner document location - otherwise I'd have problems with same origin policy.
That said, I wan't to turn this:
<html>
<head>
...
</head>
<body>
...page contents...
</body>
</html>
into this:
<html>
<head>
...here is my userscript running...
</head>
<body>
<iframe style="width: 100%; height: 100%">
...move the whole original window here...
</iframe>
</body>
</html>
Unles a link has target="_blank/_parent/_top" all browsing activity should happen in the inner iframe, while the parent window shall not be refreshed (which would cause the script lose all variables).
One way to do that would be simply creating an iframe with same url like the url of my site:
var container = document.createElement("iframe");
container.src = window.location;
However, such approach would cause page reload as well as lose of all data (filled forms, scrolling).
So to move the window with all its contents to an iframe. Is that possible?
Perhaps you could get the contents of document.head.outerHTML and document.body.outerHTML, combine them into a string, base64 encode it, then use the result to construct a dataURL, which you then set as the iframe's src.
Though I could see recursion turning the idea into an effect similar to pointing a video camera at a screen showing it's outut.
Interesting question. Bookmarked.
I need to load an external webpage into a div. I don't want to use an iFrame. And I want this done with plain Javascript. I'm not sure how to go about it.
With difficulty…
Use Ajax (e.g. via XMLHttpRequest) to get the page. Since it is external, you will need to bypass the same origin policy.
Once you have the page, extract the relevant parts of it (probably the children of the body element) and add that to your existing DOM.
You'll need to account for differing stylesheets between your site and the external one, for relative URIs (to resources on the external site that aren't on yours), and for any scripts in the remote content.
Whichever method you have, in js, try this instead : $('#myid').load('mylink.com')
I know only this in js.
You don't even need javascript-
but the same restrictions apply as for iframe inclusion of different domains.
<!doctype html>
<html lang="en">
<head>
<meta charset= "utf-8">
<title>test page</title>
</head>
<body>
<div>
<object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
</object></div>
</div>
</body>
</html>
You should be able to load html pages within a page using the jQuery.get() method. I'm using this method for two websites for my clients, where the individual pages are different sections of the site.
I'm unsure of the behavior you may encounter if you attempt to use this method loading full HTML pages that include header information and the body tag. I recommend using it to load HTML snippets.
jQuery.get()
I am trying to open a URL, which points to a PDF, using window.open(url). In IE, the popup window flashes and nothing happens afterwords. When I access the same url directly using IE, PDF opens up perfectly.
In the HTML below, when I click on Link, I get the PDF but window.open fails. Moreover, if I provide a direct link of PDF in window.open that also works perfectly. Could any body shed some light on this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
Link
<script>
url = "http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9NDk2Mjl8Q2hpbGRJRD0tMXxUeXBlPTM=&t=1";
window.open(url);
</script>
</BODY>
</HTML>
Thanks
Most browsers block window.open when is called without user interaction in order to avoid popup advertisements.
Why are doing this anyway? Instead you should link directly to the PDF in the original document, where you can use target="_blank" if it must be in a new window. (Keep in mind, that there are users that don't like it if websites open new windows).
This may just be my convention, but I always use window.open() like this:
var win = window.open(url);